使用 SMTPClient 在 VB.NET 中检查邮件是否成功发送
我正在尝试创建一个将电子邮件发送到 smtp 服务器的应用程序。
服务器不是固定设置的,而是根据电子邮件应发送到的电子邮件地址的域部分来查找。
示例:
电子邮件发送至:[email protected]
域部分:stackoverflow.com
MX 记录查找的结果(命令行“nslookup -type=mx stackoverflow.com":
stackoverflow.com MX 首选项 = 30,邮件交换器 = stackoverflow.com.s9b1.psmtp.com stackoverflow.com MX 首选项 = 40,邮件交换器 = stackoverflow.com.s9b2.psmtp.com stackoverflow.com MX 首选项 = 10,邮件交换器 = stackoverflow.com.s9a1.psmtp.com stackoverflow.com MX 首选项 = 20,邮件交换器 = stackoverflow.com.s9a2.psmtp.com
这对于了解邮件服务器是否接受邮件以及邮件是否已成功发送非常有用。
到目前为止,我能够通过使用 System.Net.Mail.SMTPClient 对象及其 SendAsync 函数来获取 SMTP 服务器错误代码(如果有错误 (StatusCode 5xx))。错误,我在 SMTPClient 的回调事件中收到异常对象
我很清楚,并不是每个邮件服务器都会告诉我邮件帐户是否确实存在,然后使用错误代码拒绝我的邮件,而是只接受消息然后删除因此,我将不胜感激另一种方法来检查邮件是否已发送(注意:未阅读,这将是已读确认)
最终目的是: 尝试使用其域邮件服务器向收件人发送电子邮件,如果失败,请根据错误代码继续(用户不存在 -> 中止/邮件服务器未响应 -> 使用另一个邮件服务器(如果可用))。
提前致谢(并对拼写错误表示歉意:))
I'm trying to create an application that sends an email to an smtp-server.
The server is not set fixed, but will be looked up according to the domainpart of the email-address where the email should be sent to.
Example:
Email To: [email protected]
Domain-Part: stackoverflow.com
Result of a MX-Record Lookup (commandline "nslookup -type=mx stackoverflow.com":
stackoverflow.com MX preference = 30, mail exchanger = stackoverflow.com.s9b1.psmtp.com
stackoverflow.com MX preference = 40, mail exchanger = stackoverflow.com.s9b2.psmtp.com
stackoverflow.com MX preference = 10, mail exchanger = stackoverflow.com.s9a1.psmtp.com
stackoverflow.com MX preference = 20, mail exchanger = stackoverflow.com.s9a2.psmtp.com
It would be quite useful, to know if the message was accepted by the mailserver and the message was successfully sent.
What I am able so far is, that I can get the SMTP-Server error code (if there was an error (StatusCode 5xx) by using the System.Net.Mail.SMTPClient Object and its SendAsync Function. There, if there was an error, I get an Exception-Object in the Callback-Event of the SMTPClient
I'm well aware that not every mailserver will tell me if the mailaccount truly exists and then reject my mail with an errorcode but instead just accept the message and then delete it. Therefore I would be grateful for another Method to check if the mail was sent (note: not read, that would be the read confirmation)
The final purpose would be:
Try to send an email to a recipient using it's domains mailserver and if it fails, proceed according to the errorcode (user does not exist -> abort / mailserver did not respond -> use another mailserver if available).
Thanks in advance (and sorry for typos :))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您正在寻找的东西不存在。电子邮件经历了如此多的跳跃,以至于没有定义“已发送”的实际含义。例如,您的 stackoverflow 示例实际上指向 Postini 的电子邮件服务器。 Postini 可能会将电子邮件从网关传递到 AV 和路由器。从那里,他们要么汇集电子邮件,要么将它们传递到另一个电子邮件服务器。
对于电子邮件,“已发送”最接近的定义是“至少我没有收到错误”。
另外,这是一件小事,但是在使用 nslookup 时请记住在域中添加尾随句点,否则将使用域搜索列表。一般来说没什么大不了的,但偶尔它可能会让你绊倒。
Unfortunately what you are looking for does not exist. Email jumps through so many hops that there is no definition of what "sent" actually means. For instance, your example of stackoverflow actually points to Postini's email servers. Postini probably passes the email around from gateways to AV's and routers. From there they either pool email or pass them on to another email server.
With email, the closest definition of "sent" is "at least I didn't get an error".
Also, a minor thing, but when using nslookup remember to add a trailing period to the domain, otherwise the domain search list is used. Generally not a big deal but every once in a while it might trip you up.