Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在C#中跟踪gmail投递子系统拒绝的电子邮件?_C#_Smtpclient - Fatal编程技术网

有没有办法在C#中跟踪gmail投递子系统拒绝的电子邮件?

有没有办法在C#中跟踪gmail投递子系统拒绝的电子邮件?,c#,smtpclient,C#,Smtpclient,我试着用一封不存在的电子邮件来测试 ... mail.To.Add(new MailAddress("nonexistenceemail@gmail.com")); mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; SmtpClient client= new SmtpClient(); client.SendCompleted += new SendCompletedEventHandler(Se

我试着用一封不存在的电子邮件来测试

...
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#代码中,有没有一种方法可以识别此类被拒绝的电子邮件

当您的电子邮件被拒绝时,这会在邮件成功发送后发生。例如,邮箱可能已满,不存在邮件地址等。 您必须获取电子邮件并检查其标题,以便能够为您的系统提供失败的原因。 不幸的是,大多数电子邮件提供商不会立即发回这些错误,因此没有简单易行的“现场”方式,也不是所有提供商都遵守RFC,特别是小型特殊公司的设置

也许你可以从RFC中获得解决这些问题的灵感