Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 340
Sankar M Avatar asked Aug 17 '11 15:08

Sankar M


3 Answers

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.
like image 63
Andrey Agibalov Avatar answered Nov 10 '22 07:11

Andrey Agibalov


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.

like image 9
Jamie Dixon Avatar answered Nov 10 '22 08:11

Jamie Dixon


Here are some best practices to ensure email deliverability:

  • Set up a single no reply address as an actual inbox and then go into the email account using pop3 and look for bounce back messages.
  • Verify the email address is valid before you send it using something like this email validation library:

http://www.kellermansoftware.com/p-37-net-email-validation.aspx

like image 1
Greg Finzer Avatar answered Nov 10 '22 07:11

Greg Finzer