技术采撷

163邮件服务器EnableSsl 需要设置为true

在服务器监控的项目中,采用SmtpClient(邮件服务器采用163)发送总是不成功,后来发现是因为EnableSsl 属性需要设置为true;这也许是163邮件服务器的强制要求,具体代码见下:

String to = ConfigurationManager.AppSettings["toList"];
String from = "xiashiwendao@163.com";
String body = String.Format("服务器:{0}<br/>异常:{1}<br/><br/>请尽快处理!", pServerName, pExceptionMsg);
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
foreach (string item in to.Split(';'))
{
    message.To.Add(item);
}
message.Subject = "业μ务?服t务?器÷异ì常£报¨警ˉ";
message.Body = body;
message.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.Port = 25;
client.Host = "smtp.163.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("xiashiwendao@163.com", "Lorry//2");
client.Send(message);
if (this.IsTestMode())
    MessageBox.Show("OK, Send Mail Complete");

posted on 2014-03-10 00:07  张叫兽的技术研究院  阅读(292)  评论(0编辑  收藏  举报

导航