How to check if the mail has been sent successfully

74,227

Solution 1

if your SmtpMail.Send(message) method returns no error, it means the email was sent to the SMTP server, then you are out of your jurisdiction, that is how far you can know.

Solution 2

Put the .Send(msg) method in a try catch block, and catch SmtpFailedRecipientException.

try
{
    mail.Send(msg);
}
catch (SmtpFailedRecipientException ex)
{
    // ex.FailedRecipient and ex.GetBaseException() should give you enough info.
}

Solution 3

If you're using System.Net.Mail try out

message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;

Solution 4

According to spec:

S: 220 smtp.example.com ESMTP Postfix
C: HELO relay.example.org
S: 250 Hello relay.example.org, I am glad to meet you
C: MAIL FROM:<[email protected]>
S: 250 Ok
C: RCPT TO:<[email protected]>
S: 250 Ok
C: RCPT TO:<[email protected]>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: "Bob Example" <[email protected]>
C: To: Alice Example <[email protected]>
C: Cc: [email protected]
C: Date: Tue, 15 Jan 2008 16:02:43 -0500
C: Subject: Test message
C:
C: Hello Alice.
C: This is a test message with 5 header fields and 4 lines in the message body.
C: Your friend,
C: Bob
C: .
S: 250 Ok: queued as 12345
C: QUIT
S: 221 Bye
{The server closes the connection}

As soon as server says 250 Ok: queued as 12345, you cannot know for sure if it had really sent an email or not, or whether it was delivered.

Solution 5

You can use the DeliveryNotificationOptions to receive a receipt.

If you have a MailMessage object named mail, do this:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
Share:
74,227
Vaibhav Jain
Author by

Vaibhav Jain

IT professional

Updated on July 18, 2022

Comments

  • Vaibhav Jain
    Vaibhav Jain almost 2 years

    I am developing an Asp.Net application, where I am sending a mail to the user's email address, if he forgets the password.

    I want to check if the mail has been sent sucessfully or not. Is there any method to know that for sure.

    EDIT

    In case if an email id does'nt exists, then would I detect a failure.