如何在C#.Net中检测“发送失败邮件"? [英] How to detect 'Sending Failure mails' in C#.Net ?

查看:56
本文介绍了如何在C#.Net中检测“发送失败邮件"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码块:

Code Block:

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
             System.Net.NetworkCredential cred = new System.Net.NetworkCredential(userName, pwd);
             mail.To.Add(" ");
             mail.Subject = " ";
             mail.From = new System.Net.Mail.MailAddress("");
             mail.IsBodyHtml = true;
             mail.Body = "";
             mail.Attachments.Add(new Attachment(""));
             try
             {
                 System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(" ");
                 smtp.UseDefaultCredentials = false;
                 smtp.EnableSsl = Convert.ToBoolean(" ");
                 smtp.Credentials = " ";
                 smtp.Port = " ";
                 smtp.Send(mail);
                 MessageBox.Show("Mail sent sucessfully");
             }
             catch(Exception ex)
             {
                 MessageBox.Show("Mail sending Failed" + ex.Message);
             }



使用上面的代码,我将发送一封带有附件的电子邮件.客户数.但我无法检测到否. 失败邮件"的代表,即向其发送邮件失败的客户端.

例如.邮寄至:abc @ com,xyz @ com,lmn @ com

请帮忙.
谢谢.



Using the above code I am sending an email with attachment to no. of clients simultaneously. But I''m not able to detect the no. of "Failure Mails" i.e. the clients to whom the mail sending is failed.

eg. Mail To : abc@com,xyz@com,lmn@com

Please Help.
Thanks.

推荐答案

在您的catch块中,使用适当的日志和计数器来跟踪故障.有什么阻止您的吗?
In your catch block, keep a track of failures using a proper log and counter. Anything stopping you here?


好了,您现在无法赶上交付失败. SMTP聊天将成功,但是邮件服务器随后可能会发现目标服务器已关闭或电子邮件用户名不存在.这可能会导致跳动,具体取决于服务器的设置方式.要检查此类退回的电子邮件,您必须将邮件回弹并解析它们以查找退回的电子邮件.
Well you cannot catch delivery failures at this point. The SMTP chat will succeed, but the mail server may then find that the destination server is down or the email username non-existent. This may result in a bounce depending on how the server is setup. To check for such bounced emails you''d have to POP the mails back and parse them for bounced emails.


这篇关于如何在C#.Net中检测“发送失败邮件"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆