tags:

views:

447

answers:

3

Hello Everyone,

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!!

+4  A: 

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.

Mehrdad Afshari
+5  A: 

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.

alex
That's really the only way to do it (with images). Construct the email so it's really hard to read if images aren't loaded. Annoying to recipient, but gets the job done if you *really* need it.
colithium
@colithium You are correct, however I wouldn't recommend your solution.
alex
Felipe Lima
I know for a fact that one mass newsletter emailing program does this - parses the email for links, creates a random hash per link and inserts it into the database. The links then become yoursite.com/link?ab27dbd9s0s89 or similar. When the request comes in, it updates the database for the hash (which maps to one email address) and then just sends location headers to the link they requested.
alex
A: 

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.

Jack Leow