以HTML方式显示内容发送邮件,需要将 isBodyHtml设置为true,同时将传进来的邮件内容,以HTML的形式传进来即可,且邮件HTML布局需要用Table来完成布局。
public class Email
{
static Logger logger = LogManager.GetCurrentClassLogger();
public static void SendMail(string ReceiverMail, string mailSubject, string mailBody)
{
MailMessage msg = new MailMessage();
msg.SubjectEncoding = Encoding.UTF8;
msg.BodyEncoding = Encoding.UTF8;
msg.Subject = mailSubject; //标题
msg.Body =mailBody; //内容
msg.IsBodyHtml = true; //邮件内容是否以HTML形式
msg.From = new MailAddress("发件箱",“收件人看到的显示的名称”);
msg.To.Add(ReceiverMail);//收件人
SmtpClient client = new SmtpClient(); //传输协议
client.Host = smtp.qq.com //邮箱服务器地址
client.Port = 25; //端口
NetworkCredential credential = new NetworkCredential();
credential.UserName = “发件箱”;
credential.Password = “密码”;
client.Credentials = credential; //代理证书credential
try
{
client.Send(msg); //发送邮件
msg.Dispose();
client.Dispose();
}
catch (Exception ex)
{
logger.Error(ex);
}
}
}