c#MailMessage类-如何验证服务器是否执行了邮件 [英] c# MailMessage class - How to verify server carried out the message

查看:39
本文介绍了c#MailMessage类-如何验证服务器是否执行了邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (MailMessage message = new MailMessage())
                {
                    message.From = new MailAddress(userEmail.InnerText);
                    message.To.Add(new MailAddress("myemail@email.com"));
                                      message.Subject = selection.Text;
                    message.Body = htmlBody();
                    message.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient("142.16.0.142"); 
                    client.Send(message);

                }

如何验证client.send(消息)成功?

How do I verify client.send(message) succeded?

推荐答案

try..catch 块内放入 Send()方法并捕获 SmtpFailedRecipientsException :

Put Send() method inside try..catch block and catch SmtpFailedRecipientsException:

try
{
   client.Send(message);
}
catch(SmtpFailedRecipientsException smtpFex)
{
    string failedRecipient = smtpFex.FailedRecipient;
    // it will return FailedRecipient's emailID. Now check the value of failedRecipient 
    //and take the action/s.
}

这篇关于c#MailMessage类-如何验证服务器是否执行了邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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