0
我试图使用一个不存在的电子邮件来测试。有没有办法在C#中跟踪来自gmail传递子系统的被拒绝的电子邮件?
...
mail.To.Add(new MailAddress("[email protected]"));
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient client= new SmtpClient();
client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
client.SendAsync(mail, "Send Async");
回调定义如下:
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
e.Cancelled || e.Error != null ? doSomething("fail") : doSomething("success");
}
然后当我检查邮箱,有来自Gmail的传送子系统被拒绝的电子邮件。
Delivery to the following recipient failed permanently:
[email protected]
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for ...
The error that the other server returned was:
550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 http://support.google.com/mail/bin/answer.py?answer=6596 cy1si14769573pdb.248 - gsmtp
然而,SendCompletedCallback告诉有没有取消或错误,它可能不会专做回调以这种方式。在C#代码中,有没有一种方法可以识别被拒绝的电子邮件?