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();
    
  • 相关阅读:
    pyinstaller 打包后无法运行
    Android Uiautomator2 gradlew 坑
    JNDI 在 J2EE 中的角色
    23种设计模式
    Struts2工作原理
    SpringMVC工作原理
    堆内存设置
    安装和使用 memcached
    SQL面试题及答案
    30多条mysql数据库优化方法,千万级数据库记录查询轻松解决
  • 原文地址:https://www.cnblogs.com/xuanlanbinfen/p/6756115.html
Copyright © 2011-2022 走看看