How to confirm that mail has been delivered or not?

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 System.Net.Mail.SmtpClient();
oMail.From = new System.Net.Mail.MailAddress("[email protected]");
oMail.To.Add(TextBox1.Text.Trim());
oMail.Subject = "Subject*";
oMail.Body = "Body*";
oMail.IsBodyHtml = true;
smtp.Host = "smtp.sendgrid.net";
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("myusername", "mypassword");
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.Send(oMail);

Here I need to check whether that mail has been delivered or not.


Solution 1:

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:

  1. There's no guarantee your message is sent as soon as you call smtp.Send().
  2. Since SMTP is routed, you can't be sure that some node on the route won't fail with delivery to uplink.

Solution 2:

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.