确定电子邮件是否可以成功发送
我正在使用 C# 编写邮件应用程序,基本上,我需要能够确定哪些收件人成功收到消息,哪些收件人没有收到消息,无论失败原因是什么。
总之,例如,当电子邮件地址不存在时,我需要抛出异常。 但是,在这种情况下,SmtpClient.Send 不会引发异常,因此我可能需要监视传递失败回复并解析它们。
我知道这不是一个简单的任务,所以我想请教各位专家一些关于如何处理电子邮件发送主要问题的提示。
提前致谢!!
I am working in a mailing application in C# and, basically, I need to be able to determine which recipients successfully received the message, which ones did not, no matter what was the failure reason.
In summary, I need an exception to be thrown whenever the email address does not exist, for example. However, SmtpClient.Send does not throw an exception in this case, so I'd need to monitor the delivery failure replies and parse them, maybe.
I know this is not a simple task, so I'd ask you experts some tips on how to handle the main issues with email sending.
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您使用带有您跟踪的哈希值或类似的图像,否则出于安全原因,我认为您无法这样做。 许多邮件客户端也不会自动下载图像。
想象一下,垃圾邮件发送者是否能够可靠地确定他们收到了哪些电子邮件?
您可以尝试 ping 服务器...即 gmail.com,但我也不知道这有多可靠。
Unless you used images with hashes you track or similar, I don't think you will be able to for security reasons. A lot of mail clients don't automatically download images too.
Imagine if spammers could reliably determine which of their emails were being received?
You could try ping the server... i.e. gmail.com but I don't know how reliable this will be either.
您无法可靠地检测到这一点。 这是 SMTP 协议的本质。 是否通知您电子邮件是否已送达完全取决于收件人 SMTP 服务器。
There's no way you could detect that reliably. It's the nature of SMTP protocol. It's completely up to the recipient SMTP server to choose to tell you if the email is delivered or not.
您的具体请求根本无法以高效的方式实现。 即使您要使用退回邮件来确定电子邮件是否已成功发送,退回邮件通常不会立即出现,有时可能需要几个小时,这意味着您确实不应该尝试同步执行此操作(即,如果未收到电子邮件,发送电子邮件的方法将抛出异常)。
不过,根据您想要执行的操作,您也许可以通过异步执行此操作来满足您的要求。 例如,我与一个拥有邮件列表应用程序的客户合作,如果电子邮件被退回,他们不需要立即处理。 他们甚至不需要可靠地知道这一点(即,如果没有收到电子邮件,但没有退回,他们不在乎)。 他们只需要知道电子邮件无效,然后取消订阅即可。
该应用程序使用了 LISTSERV。 发送的电子邮件具有自定义的、唯一的返回路径标头。 在收到来自特定收件人的 N 次退回邮件后,该电子邮件将自动取消订阅,并且与该收件人关联的任何数据库记录也会被清除。
我不确定是否有一种简单的方法可以在没有 LISTSERV 的情况下实现此目的,但您可能需要研究 smtp2web。
Your specific request simply cannot be implemented in a performant manner. Even if you were to use bounce e-mails to determine if an e-mail was successfully sent, the bounce generally won't come immediately, and may sometimes take hours, which means you really shouldn't try and do this synchronously (i.e., expect the method that sent the e-mail to throw an exception if the e-mail wasn't received).
Depending on what you want to do though, you may be able to meet your requirement by doing this asynchronously. For instance, I worked with a client that had a mailing list application where they did not need to handle it immediately if an e-mail bounced. They did not even need to know this reliably (i.e., if an e-mail isn't received, but it's not bouncing, they didn't care). They just needed to know that an e-mail is invalid, and unsubscribe it.
This application used LISTSERV. E-mails sent have a custom, unique Return-Path header. Upon receiving N bounces from a particular recipient, the e-mail is automatically unsubscribed, and any database records associated with the recipient is cleaned up as well.
I'm not sure if there's an easy way to implement this without LISTSERV, but you may want to look into smtp2web.