我正在使用.NET发送电子邮件。我正在使用DL for MailMessage.From。如果因错误的收件人电子邮件ID而无法发送电子邮件,DL本身或个人如何收到失败通知?
失败通知电子邮件不会发送到DL。虽然他们在使用" FROM"中的个人电子邮件ID时可以正常工作。我尝试在ReplyTo中添加个人电子邮件ID,但它没有用。
请建议。
答案 0 :(得分:0)
正如您在问题中已经提到的,当您在"来自"中指定个人电子邮件地址时,您确实会收到失败通知。地址,我将回答您问题的第二部分,您希望将通知发送到DL。
根据传送状态通知(DSN)的SMTP服务扩展rfc 3461,禁止向DL发送状态通知。根据此协议 5.2.7.1邮件列表:
部分重要的是,DSN不能由MTA发布(报告 成功交付到列表)和列表(报告消息 拒绝使用"失败" DSN。)
这就是为什么您的代码可以使用个人电子邮件地址正常工作,但无法使用DL
答案 1 :(得分:0)
您应该尝试SmtpFailedRecipientsException。请在此处找到代码段
public static void RetryIfBusy(string server)
{
MailAddress from = new MailAddress("ben@contoso.com");
MailAddress to = new MailAddress("jane@contoso.com");
MailMessage message = new MailMessage(from, to);
// message.Subject = "Using the SmtpClient class.";
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
// Add a carbon copy recipient.
MailAddress copy = new MailAddress("Notifications@contoso.com");
message.CC.Add(copy);
SmtpClient client = new SmtpClient(server);
// Include credentials if the server requires them.
client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an e-mail message to {0} using the SMTP host {1}.",
to.Address, client.Host);
try
{
client.Send(message);
}
catch (SmtpFailedRecipientsException ex)
{
for (int i = 0; i < ex.InnerExceptions.Length; i++)
{
SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
if (status == SmtpStatusCode.MailboxBusy ||
status == SmtpStatusCode.MailboxUnavailable)
{
Console.WriteLine("Delivery failed - retrying in 5 seconds.");
System.Threading.Thread.Sleep(5000);
client.Send(message);
}
else
{
Console.WriteLine("Failed to deliver message to {0}",
ex.InnerExceptions[i].FailedRecipient);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in RetryIfBusy(): {0}",
ex.ToString() );
}
}
请参阅此链接了解更多详情 MSDN Link