开发者

Check if mail was successfully sent in VB.NET with SMTPClient

开发者 https://www.devze.com 2023-03-20 05:19 出处:网络
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

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: test@stackoverflow.com

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 stackoverflo开发者_如何学编程w.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 :))


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.

nslookup -type=mx stackoverflow.com.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号