私はforループに入り、別の機能を使って電子メールを送ります。キャッチして続けてください
エラーが発生した場合、問題が発生したメールの後にメールを送信し続けることはありません。
私はこのエラーを検出し、システムが残りの電子メールを送信し続けたいと思います。以下のコードをご覧ください。
あなたはforeach文の内側try catch
ブロックを移動する必要が
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;
}
}
なぜ私は投票されていますか? –