日常记录
1、好像ABP.NET CORE 已经封装好了(using System.Net.Mail; ) ,我先创建一个发送邮件的类;
using System; using System.Collections.Generic; using System.Net.Mail; using System.Text; namespace ABBWAP.SendEmails { public class SendEmail { /// <summary> /// 邮件发送 /// </summary> /// <param name="Subject"></param> /// <param name="Body"></param> /// <param name="mailTo"></param> /// <param name="IsBodyHtml"></param> /// <returns></returns> public bool Send_Email(string Subject, string Body, string mailTo, bool IsBodyHtml = false) { string smtpServer = "smtp.qq.com"; //SMTP服务器 string mailFrom = "85227967@qq.com"; //登陆用户名,邮箱 string userPassword = "nlgjlwvlqhtx";//注意授权码 不是登录密码 (百度怎么弄授权码) SmtpClient smtpClient = new SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 smtpClient.Host = smtpServer; //指定SMTP服务器 smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用户名和密码 MailMessage mailMessage = new MailMessage(mailFrom, mailTo); // 发送人和收件人 mailMessage.Subject = Subject;//主题 mailMessage.Body = Body;//内容 mailMessage.BodyEncoding = Encoding.UTF8;//正文编码 mailMessage.IsBodyHtml = IsBodyHtml;//设置为HTML格式 mailMessage.Priority = MailPriority.Low;//优先级 try { smtpClient.Send(mailMessage); // 发送邮件 return true; } catch (SmtpException ex) { return false; } } } }
2、哪里需要使用发送邮件就new一下上面创建的邮件类
SendEmail email = new SendEmail(); string[] emailList = new string[] { "7888888888@qq.com"}; foreach (var item in emailList) { email.Send_Email("定时执行考勤异常数据收录", "定时执行考勤异常数据收录", item); }