配置 163 邮箱
1) 开启 SMTP 服务
2) 申请 "授权密码"
邮件发送功能
using System; using System.Net; using System.Net.Mail; using System.Text; namespace Demo_Send_163_Mail { class Program { static void Main(string[] args) { var _mailBody = System.IO.File.ReadAllText("邮件内容"); var msg = new MailMessage { IsBodyHtml = true, BodyEncoding = Encoding.UTF8, From = new MailAddress("发件人@163.com"), Subject = "邮件标题", Body = _mailBody }; msg.To.Add(new MailAddress("收件人@163.com")); var client = new SmtpClient { Host = "smtp.163.com", Port = 25, EnableSsl = true, UseDefaultCredentials = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential("发件人@163.com", "2)申请的授权密码") }; client.Send(msg); Console.WriteLine("邮件发送完了..."); Console.ReadLine(); } } }
参考资料
https://blog.csdn.net/hynkoala/article/details/112678464