【发布时间】:2018-02-20 07:12:48
【问题描述】:
我有一些代码进入 for 循环,然后使用另一个函数发送电子邮件。
当出现错误时,它不会在出现问题的电子邮件之后继续发送电子邮件。
我希望能发现错误并让系统继续发送其余的电子邮件。请看下面的代码。
public static SendEmailResult setEmailAndSend(DataRow[] rows)
{
try
{
SendEmailResult results = new SendEmailResult();
foreach (DataRow row in rows)
{
try
{
//Set Values here
string strFN = row["FirstName"].ToString();
string strLN = row["LastName"].ToString();
string strEmail = row["Email"].ToString();
//some more here
Sent = EmailFunctions.SendEmail(strEmail, strFromAddress, strFromName, strSubject, strFN + " " + strLN, strBody, strSignOffEmbeddedImagePath, strSignOffEmbeddedImageName, strCCReminderEmail);
}
catch (Exception exc)
{
//do stuff
continue;
}
}
}
catch (Exception exc)
{
//do something
}
}
public static bool SendEmail(String strToAddress, String strFromAddress, String strFromName, String strSubject, String strRecipientName, String strBody, String strEmbeddedImagePath, String strEmbeddedImageName, String strCCReminderEmail)
{
try
{
//SMTPClient settings in webconfig
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
using (MailMessage message = new MailMessage(
new MailAddress(strFromAddress, strFromName),
new MailAddress(strToAddress, strRecipientName)))
{
message.IsBodyHtml = true;
message.Subject = strSubject;
message.Body = strBody;
if (!string.IsNullOrEmpty(strCCReminderEmail))
message.CC.Add(strCCReminderEmail);
client.Send(message);
return true;
}
}
catch (Exception ex)
{
throw;
}
}
【问题讨论】:
-
为什么我被否决了。
标签: asp.net exception try-catch