SMTP 发送获取 SmtpFailedRecipientException
SMTP Send get SmtpFailedRecipientException
这是我的问题。我正在向几个联系人发送电子邮件,如果存在无效的电子邮件地址,我会收到错误消息。
基本上,它是有效的,但是如果有超过 1 个无效的电子邮件,我不会收到其他错误电子邮件地址的通知。
data = XMLProcessing.LoadAll();
foreach (XMLData.StructReceiver user in data.Receiver)
{
AddReceiver(user.Mail);
}
SetSubject(data.Body.Subject);
SetMessage(data.Body.Content);
SetSender(data.SenderReply.Sender);
SetReply(data.SenderReply.Replyer);
try
{
SMTP.Send(Message);
}
catch (SmtpFailedRecipientException e)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
finally
{
SMTP.Dispose();
}
我通过将联系人添加到列表中然后将此列表发送到我的个人电子邮件地址来接收通知,但捕获只会发生一次,即使有超过 1 个错误地址。
参见 SmtpFailedRecipientsException
。请注意,这是一个不同的 class、SmtpFailedRecipientsException。这个class其实子classes SmtpFailedRecipientException
(没有s).
你会想要先了解 SmtpFailedRecipientsException
(更具体的类型),然后再了解更一般的类型。
除了从其父级继承的字段外,它还提供 InnerExceptions
(再次注意复数 s)。这是有关 all 地址发送失败的异常集合。您可以按照 MSDN 文章所述遍历它:
try
{
SMTP.Send(Message);
}
catch (SmtpFailedRecipientsException exs)
{
foreach (SmtpFailedRecipientException e in exs)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
}
catch (SmtpFailedRecipientException e)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
finally
{
SMTP.Dispose();
}
这是我的问题。我正在向几个联系人发送电子邮件,如果存在无效的电子邮件地址,我会收到错误消息。
基本上,它是有效的,但是如果有超过 1 个无效的电子邮件,我不会收到其他错误电子邮件地址的通知。
data = XMLProcessing.LoadAll();
foreach (XMLData.StructReceiver user in data.Receiver)
{
AddReceiver(user.Mail);
}
SetSubject(data.Body.Subject);
SetMessage(data.Body.Content);
SetSender(data.SenderReply.Sender);
SetReply(data.SenderReply.Replyer);
try
{
SMTP.Send(Message);
}
catch (SmtpFailedRecipientException e)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
finally
{
SMTP.Dispose();
}
我通过将联系人添加到列表中然后将此列表发送到我的个人电子邮件地址来接收通知,但捕获只会发生一次,即使有超过 1 个错误地址。
参见 SmtpFailedRecipientsException
。请注意,这是一个不同的 class、SmtpFailedRecipientsException。这个class其实子classes SmtpFailedRecipientException
(没有s).
你会想要先了解 SmtpFailedRecipientsException
(更具体的类型),然后再了解更一般的类型。
除了从其父级继承的字段外,它还提供 InnerExceptions
(再次注意复数 s)。这是有关 all 地址发送失败的异常集合。您可以按照 MSDN 文章所述遍历它:
try
{
SMTP.Send(Message);
}
catch (SmtpFailedRecipientsException exs)
{
foreach (SmtpFailedRecipientException e in exs)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
}
catch (SmtpFailedRecipientException e)
{
if (e.FailedRecipient.ToString() != data.SenderReply.Replyer)
{
Failed.Add(e.FailedRecipient.ToString());
}
}
finally
{
SMTP.Dispose();
}