我想知道如何让我的邮件正文使用HTML?当我在使用此代码时收到电子邮件时,我不会收到它只是作为文本发送的错误。
这是我的代码:
var fromAddress = new MailAddress("example@gmail.com", "Bivar PDMTool");
var toAddress = new MailAddress("example@bivar.com", "PDMTool");
const string fromPassword = "REMOVED";
const string subject = "Plant Completed PM3-PM5-PR Project";
const string body = "Plant has completed their data entry on the <span style='text-decoration: font-family: arial, helvetica, sans-serif;'><em>PM3-PM5-PR</em></span> project on PDMTool.<br><br> http://pdmtool.bivar.com/ ";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
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);
}
}
谢谢
答案 0 :(得分:1)
更改
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
到
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true;
})
{
smtp.Send(message);
}