Normally, I'd send emails like that:
int statusCode = 0;
string error = null;
try
{
smtp.Send(mailMessage);
statusCode = 250;
}
catch (SmtpFailedRecipientException e)
{
Log(String.Format("[Exception] {0}\n\tSmtp: {1}{2}:{3}\n\tStatus Code: {4}\n\tFaild Recipient: {5}", e.Message, smtp.Key, smtp.Value.Host, smtp.Value.Port, e.StatusCode, e.FailedRecipient));
statusCode = (int)e.StatusCode;
error = e.Message;
}
catch (SmtpException e)
{
Log(String.Format("[Exception] {0}\n\tSmtp: {1} - {2}:{3}\n\tStatus Code: {4}", e.Message, smtp.Key, smtp.Value.Host, smtp.Value.Port, e.StatusCode));
statusCode = (int)e.StatusCode;
error = e.Message;
}
catch (Exception e)
{
Log(String.Format("[Exception] {0}.\n\tSource: {1}\n\tStack Trace: {2}", e.Message, e.Source, e.StackTrace));
statusCode = -1;
error = "General Failure";
}
But this method doesn't allow me to catch some of the more "advanced" SMTP errors such as No Domain, No such Email, etc.
How can I capture that kind of SMTP errors? Is that even possible?
For example, when I'm trying to send in Gmail to an address such as asdfkljhadf@dgdfasdf.com
, Gmail sends me after a while an Email that asdfkljhadf@dgdfasdf.com
doesn't exist.
Thank you.