如何在C#Email中将Body格式设置为HTML

Jac*_*All 1 c# email html5 smtp

我有以下代码来创建和发送电子邮件:

var fromAddress = new MailAddress("email@address.com", "Summary");
var toAddress = new MailAddress(dReader["Email"].ToString(), dReader["FirstName"].ToString());
const string fromPassword = "####";
const string subject = "Summary";
string body = bodyText;

//Sets the smpt server of the hosting account to send
var smtp = new SmtpClient
{
    Host = "smpt@smpt.com",
    Port = 587,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)                        
};
using (var message = new MailMessage(fromAddress, toAddress)
{                       
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}
Run Code Online (Sandbox Code Playgroud)

如何将邮件正文设置为HTML?

I a*_*ica 9

MailMessage.IsBodyHtml (来自MSDN):

获取或设置一个值,该值指示邮件消息正文是否在Html中.

using (var message = new MailMessage(fromAddress, toAddress)
{                       
    Subject = subject,
    Body = body,
    IsBodyHtml = true // this property
})
Run Code Online (Sandbox Code Playgroud)