465端口發送郵件


2017年買的阿里雲服務器 客服說暫停25端口郵件的發送  只能改為465,這樣就遇到了用web.mail 引用發送郵件
只能吧版本降到4.0


public static void SendEmail(string subject, string body, string mailTo, List<string> mailCC, List<string> attachmentUrls) { MailMessage mmsg = new MailMessage(); //驗證 mmsg.Subject = subject;// "zhuti1";//郵件主題 mmsg.BodyFormat = MailFormat.Html; mmsg.Body = body;// "wqerwerwerwer";//郵件正文 mmsg.BodyEncoding = Encoding.UTF8;//正文編碼 mmsg.Priority = MailPriority.High;//優先級 mmsg.From = "Service01@yz365.com";//發件者郵箱地址 mmsg.To = mailTo;//收件人收箱地址 StringBuilder mailCCString = new StringBuilder(); foreach (var cc in mailCC) { mailCCString.Append(cc + ";"); } mmsg.Cc = mailCCString.ToString(); foreach (var attachmentUrl in attachmentUrls) { MailAttachment oAttch = new MailAttachment(attachmentUrl, MailEncoding.Base64); mmsg.Attachments.Add(oAttch); } mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //登陸名 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "Ser@163.com"); //登陸密碼 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "登陸密碼  "); mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//端口 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com"; //企業賬號用smtp.exmail.qq.com SmtpMail.Send(mmsg); }

 

 

 string topic = "測試郵件topic";
            List<string> attachmentUrls = new List<string> { "E:\\附件.txt" };
            string body = "一封含附件的測試郵件";// "<h1>一封含附件的測試郵件</h1>";


            ClassLibrary1.MailSenderHelper.SendEmail(topic, body, "123456@qq.com", new List<string> { "7898@qq.com" }, attachmentUrls);
            Console.WriteLine("發送成功");
            Console.ReadLine();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM