【发布时间】:2013-06-19 05:07:52
【问题描述】:
我正在使用以下方法发送电子邮件。我希望能够用粗体文本格式化电子邮件。
例如
发件人:姓名
电子邮件:电子邮件地址
消息:消息
我该怎么做?
protected void SendMail()
{
var fromAddress = "myemail@gmail.com";
var toAddress = "myotheremail@gmail.com";
const string fromPassword = "mypassword";
string subject = "New Email from Website";
string body = "From: " + name.Text + "\n";
body += "Email: " + email.Text + "\n";
body += "Message: \n" + message.Text + "\n";
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
【问题讨论】:
-
创建一个 MailMessage 并设置 IsBodyHtml 属性 = true。