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();
    
  • 相关阅读:
    字符串阵列分别输出元素的索引,原值和长度
    一个字符转换为整数
    从字符串数组中寻找数字的元素
    C#创建自己的扩展方法
    判断是否为空然后赋值
    C# yield关键词使用
    从字符串数组中把数字的元素找出来
    C#实现一张塔松叶
    计算2个时间之间经过多少Ticks
    对int array进行排序
  • 原文地址:https://www.cnblogs.com/xuanlanbinfen/p/6756115.html
Copyright © 2011-2022 走看看