有没有一种方法可以用C#知道电子邮件是否成功中继?

3
有没有办法用C#知道电子邮件是否成功中继?
我正在使用System.Net.Mail。
3个回答

2
将MailMessage的DeliveryNotificationOptions属性设置为
System.Net.Mail.DeliveryNotificationOptions.OnSuccess

或者尝试:
static void ReadReceipts()
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//To request a read receipt, we need add a custom header named 'Disposition-Notification-To'
//in this example, read receipts will go back to 'someaddress@mydomain.com'
//it's important to note that read receipts will only be sent by those mail clients that 
//a) support them
//and
//b)have them enabled.
mail.Headers.Add("Disposition-Notification-To", "<someaddress@mydomain.com>");


//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}

我可以设置多个DeliveryNotificationOptions吗?谢谢。 - Gaurav Pandey
1
许多服务器 - 特别是企业服务器 - 阻止传递报告,因为它们会显示哪些电子邮件地址是有效的,从而可能导致垃圾邮件。 - Adam Hopkinson

2

要确定某人是否收到了一封电子邮件,唯一的方法是要求他们以某种方式通知您(如读取回执或类似方式)。

这就是为什么所有的电子邮件确认方案都需要您点击链接确认它是您的电子邮件的原因。


这没问题,但有时候在注册时,如果用户没有收到确认邮件(一封包含激活账户链接的邮件),我们怎么知道呢?因为我从SmtpClient类方法中没有得到任何异常。 - Gaurav Pandey
1
即使从您的服务器发送成功,也无法知道对方是否收到了邮件,它可能会在途中丢失(包括他的电子邮件提供商出于某种原因将您的电子邮件提供商列入黑名单并自动删除所有电子邮件)。我建议在用户注册后,显示一条消息,内容为“如果您在x分钟内没有收到电子邮件,请检查您的垃圾邮件文件夹,或尝试重新发送消息,或将消息重新发送到另一个电子邮件地址”。 - Hans Olsson

2
使用像Postmark这样的服务,它允许您通过SMTP或API发送邮件,并可以使用Web挂钩通知您的应用程序发送失败的消息。
Postmark使用PowerMTA,一种能够检测垃圾邮件标记、反弹等的电子邮件网关。您可以直接通过PowerMTA发送邮件,但Postmark会将所有内容包装得很好。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接