c# 坑人的发邮件组件

System.Net.Mail 在服务器25端口被封禁的情况下,无法使用其它诸如SSL 465端口发送。用过时的System.Web.Mail却可以。是微软更新速度太快呢,还是标准不一致呢。

System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
    mail.To = "nan@firstelite.net";
    mail.From = "xue@163.com";
    mail.Subject = "test";
    mail.BodyFormat = System.Web.Mail.MailFormat.Html;
    mail.Body = "test222";
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //身份验证  
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mail.From); //邮箱登录账号,这里跟前面的发送账号一样就行  
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //这个密码要注意:如果是一般账号,要用授权码;企业账号用登录密码  
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//端口  
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//SSL加密  
    System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com";    //企业账号用smtp.exmail.qq.com  
    System.Web.Mail.SmtpMail.Send(mail);
原文地址:https://www.cnblogs.com/nanfei/p/10678819.html