我曾尝试使用不存在的电子邮件进行测试。
...
mail.To.Add(new MailAddress("nonexistenceemail@gmail.com"));
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:
nonexistenceemail@gmail.com
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#代码中,有没有办法识别这种被拒绝的电子邮件?
答案 0 :(得分:0)
当您的电子邮件被拒绝时,这会在邮件成功发送后发生。例如,邮箱可以是完整的,不存在的邮件地址,依此类推。 您必须获取弹跳邮件并检查其标题,以便能够为系统提供失败的原因。 不幸的是,大多数电子邮件提供商都没有立即发回这些错误,因此没有万无一失的方法可以做到这一点"生活",也不是所有提供商都遵守RFC,特别是小型的特殊公司设置。
也许您可以从RFC中获取灵感来解决这些问题