How to check if the mail has been sent successfully

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.

Method 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.
}

Method 3

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

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

Method 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:<<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9bbb6bb99bca1b8b4a9b5bcf7b6abbe">[email protected]</a>>
S: 250 Ok
C: RCPT TO:<<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d0ddd8d2d4f1d4c9d0dcc1ddd49fd2dedc">[email protected]</a>>
S: 250 Ok
C: RCPT TO:<<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b3f232e292438380b2e332a263b272e65282426">[email protected]</a>>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: "Bob Example" <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5735383517322f363a273b3279382530">[email protected]</a>>
C: To: Alice Example <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a7b7673797f5a7f627b776a767f34797577">[email protected]</a>>
C: Cc: <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5918d80878a9696a5809d8488958980cb868a88">[email protected]</a>
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.

Method 5

You can use the DeliveryNotificationOptions to receive a receipt.

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

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

Method 6

No. E-mail (SMPT based) is an unreliable transport protocol and although there are some hacks to detect that an e-mail has been received and read, e.g. by embedding an individualized image URL in the e-mail and tracking that the image has been requested by the recipient’s client, there is no absolutely reliable way to fulfil your request.

Method 7

The SmtpClient.Send method will raise an Exception if there’s a problem sending. But beyond getting that message to the SMTP server, there’s no way to know if it makes it to the destination from there.

Method 8

I’am using gmail SMTP for sending mails with my program. A fake mail sent returns Ok even with SmtpFailedRecipientException trap.

But when I check with outlook my gmail recipient I see that mail was not sent with explanation. With a subject Delivery Status Notification (Failure)

My question is it possible to get this notificiation whitin the program.

I found this but it’s not for POP

Notify C# Client, when SMTP Server receive a new Email


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x