public static void SendEmail(SendMail M) { MailMessage myMail = new MailMessage();//发送电子邮件类 foreach (string item in M.Addressee)//添加收件人 { myMail.To.Add(item); } foreach (string item in M.CC)//添加抄送 { myMail.CC.Add(item); } myMail.Subject = M.Theme;//邮件主题 myMail.SubjectEncoding = M.SubjectEncoding;//邮件标题编码 myMail.From = new MailAddress(M.From, M.DisplayName, M.SubjectEncoding);//发件信息 myMail.Body = M.Body;//邮件内容 myMail.BodyEncoding = M.BodyEncoding;//邮件内容编码 myMail.IsBodyHtml = M.IsBodyHtml;//是否是HTML邮件 SmtpClient smtp = new SmtpClient();//SMTP协议 smtp.EnableSsl = M.EnableSsl;//是否使用SSL安全加密 使用QQ邮箱必选 smtp.Host = M.Host;//主机 smtp.Send(myMail);//发送 }
public class SendMail { public string From { get; set; }//发件人地址 public string Password { get; set; }//密码 public string[] Addressee { get; set; }//收件人地址 public string[] CC { get; set; }//抄送 public string Theme { get; set; }//主题 public string DisplayName { get; set; }//发件人名称 public Encoding SubjectEncoding { get; set; }//编码 public string Body { get; set; }//邮件内容 public Encoding BodyEncoding { get; set; }//邮件内容编码 public bool IsBodyHtml { get; set; }//是否HTML邮件 public MailPriority Priority { get; set; }//邮件优先级 public bool EnableSsl { get; set; }//是否ssl public bool UseDefaultCredentials { get; set; } public string Host { get; set; } }
原文:https://www.cnblogs.com/cdjbolg/p/14857475.html