Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 725
Vaibhav Jain Avatar asked Feb 26 '10 14:02

Vaibhav Jain


3 Answers

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.

like image 147
Francisco Aquino Avatar answered Nov 06 '22 15:11

Francisco Aquino


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.
}
like image 10
Brandon Avatar answered Nov 06 '22 15:11

Brandon


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

message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess;
like image 9
statenjason Avatar answered Nov 06 '22 14:11

statenjason