技术采撷

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

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

String to = ConfigurationManager.AppSettings["toList"];

String from = "[email protected]";

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("[email protected]", "Lorry//2");

client.Send(message);

if (this.IsTestMode())

    MessageBox.Show("OK, Send Mail Complete");

你可能感兴趣的:(技术)