FINDING OUT WHEN AN EMAIL ISN'T DELIVERED IN CODE

Hi,

Is there a way of knowing if an email or text that is sent via an asp.net 4 website is bounced or not?

Basically we want to send the email and if it bounces or isn't being delivered then somehow in code we can find this out and automae letting the user know.

Is this possible?

C# ideally.
scm0smlAsked:
Who is Participating?
 
Todd GerbertIT ConsultantCommented:
Generally, I think, the Send method (assuming you're using SmtpClient, or something similar) almost always returns success except in cases where there's an immediate failure, such as a malformed recipient address like "user@missingdotcom", or an inaccessible SMTP server.

In most cases it's up to the recipients server to generate an error (if there's no such user, e.g.), and send you a return e-mail message with a Non-Delivery Report (NDR).

I've never attempted to do so, but I imagine it might be possible to attach a custom header to the message that uniquely identifies that message, like a GUID. The address you're using as the "From" field for the message would need to be valid, and able to receive mail. You'd store some information in a database, like the recipients e-mail address, along with the GUID. Periodically you would check the sender's mailbox for NDR's, and if one is found with the custom header you added to the out-going message you can compare that GUID to ones that you previously stored in a database.

Or, I supposed you could simply check the "To" headers in any NDR's you've received as an alternative to the GUID-tracking method.
0
 
BardobraveCommented:
Actually it depends on the way you are sending the email.

However, most email libraries have some sort of error control. It could be a return value or just the throwing of an exception. You can check the result of the send method execution to see if it has been succesful or if it returns an error value or an exception (wich usually includes info about the error produced).

Check SmtpClient class documentation, as an example, for further info:
http://msdn.microsoft.com/es-es/library/h1s04he7.aspx
0
 
Todd GerbertIT ConsultantCommented:
...keep in mind that it may be days before receive any errors.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.