C# 用System.Net.Mail 发mail
最近项目中有用到SMTP 发Mail , 作个记录!
using System.Net.Mail;
using System.Net;
---------------------
MailAddress MailFrom = new MailAddress(mailFrom); --aaa@xxx.com
MailAddress MailTo = new MailAddress(mailTo); ---bbb@xxx.com
MailAddress MailCC = new MailAddress(mailCC); ---ccc@xxx.com
MailMessage HtmlMailMessage = new MailMessage(MailFrom, MailTo);
HtmlMailMessage.CC.Add(MailCC);
HtmlMailMessage.Subject = mailSubject;
HtmlMailMessage.Body = mailBody;
HtmlMailMessage.IsBodyHtml = true;
HtmlMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
HtmlMailMessage.Attachments.Add(new Attachment(mailAttachment)); -- 附件 地址
SmtpClient mailSmtpClient = new SmtpClient(mailServer); --mailServer SMTP
mailSmtpClient.Send(HtmlMailMessage);