I am sending email from within the web application using NetMail and it works fine when there is nothing wrong! I am trying to catch some of the errors, specifically wrong email address that should cause an exception but it seems it doesn't. My email address is fisrstname.dot.middleinitial.lastname@domain_name. I don't include middle initial on purpose to cause an error but when I trace the code it goes through. This is what I have:
SmtpClient sc = new SmtpClient(<Mail_relay>);
sc.Credentials = new NetworkCredential();
try
{
sc.Send(mm);
}
catch (SmtpFailedRecipientsException FRE)
{
foreach (SmtpFailedRecipientException smtpFailedRecipientException in FRE.InnerExceptions)
{
// Get the email that is causing the exception
string sFailedRecipient = smtpFailedRecipientException.FailedRecipient;
// Get the status code
SmtpStatusCode sc = FRE.StatusCode;
}
}
catch (SmtpException smtpEx)
{
SmtpStatusCode sc = smtpEx.StatusCode;
}
catch (Exception generalEx)
{
string sMessage = generalEx.Message;
}
I thought bad email address would be caught in the first catch block but it is not, it just goes right through all catch blocks.