C#电子邮件中如何将Body格式设置为HTML [英] How to set Body format to HTML in C# Email
本文介绍了C#电子邮件中如何将Body格式设置为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来创建和发送电子邮件:
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);
}
如何将邮件正文设置为HTML?
How can I set the message body to HTML?
推荐答案
MailMessage。 IsBodyHtml
(从MSDN):
MailMessage.IsBodyHtml
(from MSDN):
获取或设置一个值,指示邮件正文是否在
Html中。
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
})
这篇关于C#电子邮件中如何将Body格式设置为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文