标签:ram 发邮件 sys 邮箱 png smtp send add class
1.使用的QQ邮箱,其他也可以但是服务器名称不同
2.在QQ邮箱的邮箱设置的账户中开启SMTP服务
3.开启SMTP服务后会得到授权码(用来发邮件)
4.执行代码
/// <summary> /// 邮箱发送 /// </summary> /// <param name="userName">用户名称</param> /// <param name="pwd">授权码</param> /// <param name="server">服务器名称</param> /// <param name="toEmail">要发送的邮箱地址</param> /// <param name="title">标题</param> /// <param name="content">内容</param> public static void Mail(string userName, string pwd, string server, string toEmail, string title, string content) { using (MailMessage mailMessage = new MailMessage()) using (SmtpClient smtpClient = new SmtpClient(server)) { mailMessage.To.Add(toEmail); mailMessage.Body = content; mailMessage.From = new MailAddress(userName); mailMessage.Subject = title; smtpClient.Credentials = new System.Net.NetworkCredential(userName, pwd); //如果启用了“客户端授权码”,要用授权码代替密码 smtpClient.Send(mailMessage); } }
标签:ram 发邮件 sys 邮箱 png smtp send add class
原文地址:https://www.cnblogs.com/huaixing/p/11937038.html