您好我正在尝试使用Bold和下划线在C#
的消息中发送电子邮件<b></b> <u></u>
我如何将其实现到我的代码中?
var fromAddress = new MailAddress("test@gmail.com", "test");
var toAddress = new MailAddress("test@gmail.com", "test");
const string fromPassword = "REMOVED";
const string subject = "Engineering Completed NewParts Project";
const string body = "Engineering has completed their data entry on the <b><u>NewParts</b></u> project on PDMTool. / ";
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 :(得分:0)
修复新的MailMessage声明,如下所示:
new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true // this tells the message to be sent in HTML
}
答案 1 :(得分:0)
将the IsBodyHtml
property设为true
:
var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true
}