简体   繁体   English

如何确认邮件是否已送达?

[英]How to confirm that mail has been delivered or not?

Below is my coding, just have a look at it下面是我的代码,看一下

System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage();
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
oMail.From = new System.Net.Mail.MailAddress("one@gmail.com");
oMail.To.Add(TextBox1.Text.Trim());
oMail.Subject = "Subject*";
oMail.Body = "Body*";
oMail.IsBodyHtml = true;
smtp.Host = "smtp.sendgrid.net";
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("myusername", "mypassword");
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(oMail);

Here I need to check whether that mail has been delivered or not.在这里,我需要检查该邮件是否已送达。

You can't.你不能。 Since you use SMTP, in general case, it's impossible to tell whether delivery succeeded or not.由于您使用的是SMTP,一般情况下无法判断是否发货成功。 Read SMTP specification.阅读 SMTP 规范。 Mail is routed while being delivered, so:邮件在传递时被路由,因此:

  1. There's no guarantee your message is sent as soon as you call smtp.Send() .无法保证在您致电smtp.Send()后立即发送您的消息。
  2. Since SMTP is routed , you can't be sure that some node on the route won't fail with delivery to uplink.由于 SMTP 已路由,因此您无法确定路由上的某些节点不会因传递到上行链路而失败。

You can set the DeliveryNotificationOptions property of the MailMessage to OnSuccess .您可以将MailMessageDeliveryNotificationOptions属性设置为OnSuccess

There's more info on this here: http://msdn.microsoft.com/en-us/library/system.net.mail.deliverynotificationoptions.aspx这里有更多信息: http://msdn.microsoft.com/en-us/library/system.net.mail.deliverynotificationoptions.aspx

and here: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.deliverynotificationoptions.aspx在这里: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.deliverynotificationoptions.aspx

As has been pointed out in the comments, this method is not 100% reliable.正如评论中所指出的,这种方法不是 100% 可靠的。 It's just one option.这只是一种选择。

In case somebody stumbles across.以防有人偶然发现。 Here is my experience on an old Win 2003 server with Exchange.这是我在旧的 Win 2003 服务器上使用 Exchange 的经验。 My.Net app uses SMTP to send emails and used a group address as the "From" so any replies would go to the entire group. My.Net 应用程序使用 SMTP 发送电子邮件并使用组地址作为“发件人”,因此任何回复都会 go 到整个组。 This is a dispatching operation and we wanted anyone in the group to assist with any replies.这是一个调度操作,我们希望小组中的任何人都能协助回复。 We expected any non delivery notices to be sent to the group.我们希望将任何未交货通知发送给该组。 It does not happen.它不会发生。 I even went into the Message Tracking and saw that Exchange said it sent the notification to the group, but they never got it.我什至进入了消息跟踪,看到 Exchange 说它向群组发送了通知,但他们从未收到。 Next I went into SMTP Virtual Server Properties and entered the group email address in the "Send copy of Non-Delivery Report to:".接下来我进入 SMTP Virtual Server Properties 并在“Send copy of Non-Delivery Report to:”中输入组 email 地址。 Same result, the Message Tracking says it sent it to the group but it was never delivered.同样的结果,消息跟踪说它已将其发送到该组,但从未交付。 Apparently the non delivery notices will only be delivered to an email address of an individual not a group.显然,未送达通知只会送达个人而非团体的 email 地址。 I changed it to an individual address and it works.我将其更改为个人地址,并且可以正常工作。

Here are some best practices to ensure email deliverability:以下是确保 email 可交付性的一些最佳实践:

  • Set up a single no reply address as an actual inbox and then go into the email account using pop3 and look for bounce back messages.将单个无回复地址设置为实际收件箱,然后使用 pop3 将 go 放入 email 帐户并查找退回邮件。
  • Verify the email address is valid before you send it using something like this email validation library:验证 email 地址是否有效,然后使用类似以下 email 验证库的内容发送:

http://www.kellermansoftware.com/p-37-net-email-validation.aspx http://www.kellermansoftware.com/p-37-net-email-validation.aspx

If you don't receive any exceptions in your code or on your SMTP server, you can assume that it has been delivered.如果您的代码或 SMTP 服务器上没有收到任何异常,则可以假定它已交付。 That is a problem with e-mail, there is no way to guaranteeing delivery.那是电子邮件的问题,无法保证交付。

If you have access to the server containing the SMTP log, depending on the type of server used and the level of detail used, you might be able to get a much better idea as to the actual success of the delivery.如果您有权访问包含 SMTP 日志的服务器,根据使用的服务器类型和使用的详细程度,您可能能够更好地了解交付的实际成功。

For example if you are using SmarterMail, you could write a simple parser to read the smtp log and report back to your application.例如,如果您使用 SmarterMail,您可以编写一个简单的解析器来读取 smtp 日志并向您的应用程序报告。 Not that this shouldn't be a blocking operation, as if your email is greylisted, it may take many minutes before it is delivered.并不是说这不应该是一个阻塞操作,就像您的 email 被列入灰名单一样,它可能需要几分钟才能交付。

Another option is to create a catch all "noreply" email address, and send your emails with an email-id included in the sender ie noreply-bounces-32432@bounces.mydomain.com and use a pop3 reader to check the inbox for returned emails.另一种选择是创建一个捕获所有“noreply”email 地址,并使用发件人中包含的电子邮件 ID 发送您的电子邮件,即 noreply-bounces-32432@bounces.mydomain.com 并使用 pop3 阅读器检查收件箱电子邮件。 Using the email id in the "sender" you can work out which email failed to be sent.使用“发件人”中的 email id,您可以确定哪个 email 未能发送。 You could also do some filtering do determine if its a "unable to deliver" or simply an "out of office" type reply.您还可以进行一些过滤以确定它是“无法交付”还是仅仅是“不在办公室”类型的回复。

Lots of options available, just depends how much sweat you want to put into it.有很多选择,只取决于你想投入多少汗水。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM