【发布时间】:2011-06-30 10:50:46
【问题描述】:
通常,我会发送这样的电子邮件:
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";
}
但是这种方法不允许我捕获一些更“高级”的 SMTP 错误,例如 No Domain、No such Email 等。
如何捕获此类 SMTP 错误?这可能吗?
例如,当我尝试在 Gmail 中向 asdfkljhadf@dgdfasdf.com 等地址发送邮件时,Gmail 会在一段时间后向我发送一封 asdfkljhadf@dgdfasdf.com 不存在的电子邮件。
谢谢。
【问题讨论】: