如何在system.net.mail中发送富文本消息
时间:2020-03-06 14:46:11 来源:igfitidea点击:
如何在system.net.mail中发送富文本消息,需要以html格式发送邮件的代码
解决方案
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(); mm.Body = "<html>...</html>"; mm.IsBodyHtml = true;
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
//set the content
mail.Subject = "This is an email";
mail.Body = "<b>This is bold</b> <font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
我们应该意识到,并非每个人/邮件客户端都可以显示HTML格式的消息。如果我们依靠布局来使消息清晰,这可能是一个问题。

