2

Is there a way to check if SmtpClient successfully delivered an email? SmtpClient.Send() does not appear to return anything other than an exception. So if the method completes is it safe to assume the email will be successfully sent to the appropriate email box? My code is below:

MailMessage emailMessage = new MailMessage();
emailMessage.Subject = SubjectText;
emailMessage.IsBodyHtml = IsBodyHtml;
emailMessage.Body = BodyText;
emailMessage.From = new MailAddress(Settings.Default.FromEmail,Settings.Default.FromDisplayName);

//add recipients
foreach (string recipientAddress in RecipientAddresses.Split(new char[{','},StringSplitOptions.RemoveEmptyEntries))

emailMessage.To.Add(recipientAddress);

using (SmtpClient smtpClient = new SmtpClient())
{
smtpClient.Send(emailMessage);
}
whoblitz
  • 1,065
  • 1
  • 11
  • 17
  • No. because SMTP sucks. But yes if it didnt threw you can safely assume SmtpClient really did it's best – AK_ Feb 11 '11 at 20:37
  • Possible duplicate of [How to confirm that mail has been delivered or not?](http://stackoverflow.com/questions/7095104/how-to-confirm-that-mail-has-been-delivered-or-not) – Michael Freidgeim Feb 09 '16 at 13:00

4 Answers4

4

No, there is no reliable way to find out if a message was indeed delivered.

Doing so will require access to the end SMTP server for every person you are emailing.

If you do not get an exception, you can assume that the SMTP server did its best to deliver the email.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

There's no way to be 100% sure that a mail message has been received when sent via SmtpClient due to the way email works. The fact that SmtpClient doesn't throw an exception essentially means that you've done everything right, but a failure can happen further down the line, for example:

  • The receiving mail server could reject the mail
  • An intermediate mail server could reject the mail
  • The server that SmtpClient is transmitting mail through could decide to refuse to transmit the mail
Rob
  • 45,296
  • 24
  • 122
  • 150
1

One solution you could use is to create an httphandler for your website images. If you send an HTML message which includes at least 1 image, then you could embed querystring data to the end of that image. This could even be something like a 1x1 transparent image. When the user reads the email, this sends the request to the server to fetch the image data, and in turn, you could capture that request and denote that the message was read.

This is not bulletproof however, because most email clients block images by default unless the user specifies they would like to view images in the email.

Kyle B.
  • 5,737
  • 6
  • 39
  • 57
0

If the recipient e-mail address is valid you don't get an immediate return value about the successful delivery of the message; see the signature:

public void Send(MailMessage message)

The SMTP server will notify the sender (or whoever you specify for the notification) almost immediately with an 'Undeliverable' notification whenever the recipient e-mail address is invalid/fake.

SMTP servers are required to periodically retry delivery. When the recipient e-mail address is a valid address but for some reason the SMTP server could not deliver the message, the SMTP server will return a failure message to the sender if it cannot deliver the message after a certain period of time.

RFC 2821 contains more details.

From section 2.1 Basic Structure

In other words, message transfer can occur in a single connection between the original SMTP-sender and the final SMTP-recipient, or can occur in a series of hops through intermediary systems. In either case, a formal handoff of responsibility for the message occurs: the protocol requires that a server accept responsibility for either delivering a message or properly reporting the failure to do so.

See sections 4.5.4 and 4.5.5

From section 6.1 Reliable Delivery and Replies by Email

If there is a delivery failure after acceptance of a message, the receiver-SMTP MUST formulate and mail a notification message. This notification MUST be sent using a null ("<>") reverse path in the envelope. The recipient of this notification MUST be the address from the envelope return path (or the Return-Path: line).

Only You
  • 2,051
  • 1
  • 21
  • 34