Below is my coding, just have a look at it
System.Net.Mail.MailMessage oMail = new System.Net.Mail.MailMessage();
System.Net.Mail.SmtpClient smtp = new Syste
You can set the DeliveryNotificationOptions
property of the MailMessage
to OnSuccess
.
There's more info on this here: http://msdn.microsoft.com/en-us/library/system.net.mail.deliverynotificationoptions.aspx
and here: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.deliverynotificationoptions.aspx
As has been pointed out in the comments, this method is not 100% reliable. It's just one option.
If you have access to the server containing the SMTP log, depending on the type of server used and the level of detail used, you might be able to get a much better idea as to the actual success of the delivery.
For example if you are using SmarterMail, you could write a simple parser to read the smtp log and report back to your application. Not that this shouldn't be a blocking operation, as if your email is greylisted, it may take many minutes before it is delivered.
Another option is to create a catch all "noreply" email address, and send your emails with an email-id included in the sender ie noreply-bounces-32432@bounces.mydomain.com and use a pop3 reader to check the inbox for returned emails. Using the email id in the "sender" you can work out which email failed to be sent. You could also do some filtering do determine if its a "unable to deliver" or simply an "out of office" type reply.
Lots of options available, just depends how much sweat you want to put into it.
Here are some best practices to ensure email deliverability:
http://www.kellermansoftware.com/p-37-net-email-validation.aspx
You can't. Since you use SMTP, in general case, it's impossible to tell whether delivery succeeded or not. Read SMTP specification. Mail is routed while being delivered, so:
smtp.Send()
.In case somebody stumbles across. Here is my experience on an old Win 2003 server with Exchange. My .Net app uses SMTP to send emails and used a group address as the "From" so any replies would go to the entire group. This is a dispatching operation and we wanted anyone in the group to assist with any replies. We expected any non delivery notices to be sent to the group. It does not happen. I even went into the Message Tracking and saw that Exchange said it sent the notification to the group, but they never got it. Next I went into SMTP Virtual Server Properties and entered the group email address in the "Send copy of Non-Delivery Report to:". Same result, the Message Tracking says it sent it to the group but it was never delivered. Apparently the non delivery notices will only be delivered to an email address of an individual not a group. I changed it to an individual address and it works.
If you don't receive any exceptions in your code or on your SMTP server, you can assume that it has been delivered. That is a problem with e-mail, there is no way to guaranteeing delivery.