c# - 如何在 C# 电子邮件中将正文格式设置为 HTML

标签 c# html email 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);
}

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

最佳答案

MailMessage.<a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml.aspx" rel="noreferrer noopener nofollow">IsBodyHtml</a> (来自 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,
    <b>IsBodyHtml = true</b> // this property
})

关于c# - 如何在 C# 电子邮件中将正文格式设置为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15749368/

相关文章:

html - 如何在 Jekyll 中使用多种语言制作我的博客

html - 按从左到右的顺序将 div float 到右侧?

javascript - 无法使用 nodemailer (gmail) 启动邮件线程(回复邮件)

linux - 发送 fpdf 附件在我的 linux suse 服务器上不起作用,但它在我的共享主机帐户上起作用

c# - int 到十六进制字符串

c# - VSTO : how to set a ribbon's button from ThisAddIn class

c# - 使用 C# 将文件写入 Linux 中的网络位置

html - ERR_NAME_NOT_RESOLVED 使用 fontawesome

email - 是否可以制作一个相应回复的电子邮件机器人?

c# - 在 asp.net gridview 中更改选定行的颜色