zoukankan      html  css  js  c++  java
  • 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();
    
  • 相关阅读:
    Linux系统开发笔记
    软件测试 | Chrome 浏览器+Postman还能这样做接口测试 ?
    yum 在线安装 nginx
    画图3D Paint 3D工作区黑屏
    InfluxDB 存储结构、读、写
    纯前端保存下载文件到本地
    umijs 配置的一些用法和解释 记录
    mongodb在双活(主备)机房的部署方案和切换方案设计
    mongodb oplog详解和格式分析
    麒麟操作系统上安装docker并加载镜像
  • 原文地址:https://www.cnblogs.com/xuanlanbinfen/p/6756115.html
Copyright © 2011-2022 走看看