465端口发送邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2017年买的阿里云服务器 客服说暂停25端口邮件的发送  只能改为465,这样就遇到了用web.mail 引用发送邮件<br>只能吧版本降到4.0<br><br><br>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);
        }

 

 

1
2
3
4
5
6
7
8
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 @   荧屏  阅读(5183)  评论(6编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示