I have the following code to create and send an email:
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);
}
How can I set the message body to HTML?
解决方案
MailMessage.IsBodyHtml (from MSDN):
Gets or sets a value indicating whether the mail message body is in
Html.
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true // this property
})