我有一个带有数千封邮件的数据源,我需要做什么,它在循环中发送此邮件,但是当邮件被黑名单或无效时,我会收到错误,而其他错误邮件永远不会发送。
这很重要,因为以后的联系人永远不会收到我的传单,可以忽略失败的邮件而仍在发送的邮件?
这是我的代码的一部分:
DataView dv = (DataView)contactosSource.Select(DataSourceSelectArguments.Empty);
for (int i = 0; i < dv.Count; i++)
{
string correo = "" + dv[i][0];
MailMessage m = new MailMessage();
SmtpClient sc = new SmtpClient();
m.From = new MailAddress("carlos.ancona@dotstudio.com", "Carlos Ancona");
m.To.Add(new MailAddress(correo, correo));
m.Subject = subjectLabel.Text;
m.Body = "This is a Test Mail";
String username = "SMTPusername";
String password = "password";
sc.Host = "email-smtp.us-east-1.amazonaws.com";
sc.Port = 587;
sc.Credentials = new System.Net.NetworkCredential(username, password);
//sc.UseDefaultCredentials = true;
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(m);
}
try
{
sc.Send(m);
}
catch
{
Response.Clear();
Response.Write(Encoding.UTF8.GetString(Convert.FromBase64String(@"WW91IHNodWxkIG5vdCBzcGFtIHBlb3BsZSE=")));
}