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();

 

posted @ 2017-04-24 11:51  荧屏  阅读(5180)  评论(6编辑  收藏  举报