如果失败,请抓住邮件地址 [英] Catch the mail address if failed
问题描述
朋友们,
我使用smtp将邮件发送到多个地址,我想获取sendig失败的邮件地址。
message.To.Add(new System.Net.Mail.MailAddress(xxx@gmail.com));
message.To.Add (new System.Net.Mail.MailAddress(yyy@gmail.co.in));
message.To.Add(new System.Net.Mail.MailAddress(zzz @ gmail。 com));
client.Send(message);
在上面的列表中,第一个和第三个邮件已发送,而第二个邮件则不能。
所以我想抓住失败的邮件地址(yyy@gmail.co.in)。
解决方案请
Hi friends,
I am sending the mail to multiple address using smtp and I want to get the mail address to which got sendig failed.
message.To.Add(new System.Net.Mail.MailAddress("xxx@gmail.com"));
message.To.Add(new System.Net.Mail.MailAddress("yyy@gmail.co.in"));
message.To.Add(new System.Net.Mail.MailAddress("zzz@gmail.com"));
client.Send(message);
In the above list, for the first and third mail got sent and for the second one it cannot.
So I want to catch the failed mail address(yyy@gmail.co.in).
Solution pls
推荐答案
您需要将client.Send放在try / catch块中,例如:
You need to put the client.Send in a try/catch block, like:
try
{
message.To.Add(new System.Net.Mail.MailAddress("xxx@gmail.com"));
message.To.Add(new System.Net.Mail.MailAddress("yyy@gmail.co.in"));
message.To.Add(new System.Net.Mail.MailAddress("zzz@gmail.com"));
client.Send(message);
}
catch (SmtpFailedRecipientsException failedEx)
{
//In here, you can use the InnerExceptions (notice the s) to get the FailedRecipient
}
System.Net.Mail.SmtpFailedRecipientsException [ ^ ]
这篇关于如果失败,请抓住邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!