16

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("one@gmail.com");
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.

Michał Powaga
  • 22,561
  • 8
  • 51
  • 62
Sankar M
  • 4,549
  • 12
  • 37
  • 55

6 Answers6

21

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.
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
9

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.

Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
  • @Blindy: it's absolutely unreliable since this notification is only sent if recepient allows it (most mail clients act this way). It's the same as sending back an email: "thanks, got it". – Andrey Agibalov Aug 17 '11 at 15:20
  • 15
    You're still missing the part where it's better than literally nothing. – Blindy Aug 17 '11 at 15:23
1

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.

Rob Keller
  • 11
  • 2
1

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

Greg Finzer
  • 6,714
  • 21
  • 80
  • 125
0

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.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • Clearly Incorrect! SMTP is not a guaranteed delivery. As anyone would know that has received a not-deliverable ticket several weeks later... – Mitch Wheat Aug 17 '11 at 15:12
  • but, if any emailid bounces it doesn't shows any exception ..i have checked many times...is there any way to get the bounce mailerID – Sankar M Aug 17 '11 at 15:16
  • is der any way to get it thro' smtp mail message itself – Sankar M Aug 17 '11 at 15:24
0

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.

James Harris
  • 1,904
  • 11
  • 15