发送电子邮件与HTML文件作为体(C#)
问题描述:
如何能我设置MailMessage's机身采用了HTML文件?
How can I set the MailMessage´s body with a HTML file ?
感谢
答
刚刚成立的MailMessage.BodyFormat财产 MailFormat.Html ,然后倾倒你的HTML内容文件的MailMessage.Body属性:
Just set the MailMessage.BodyFormat property to MailFormat.Html, and then dump the contents of your html file to the MailMessage.Body property:
using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your
{ // HTML file
MailMessage myMail = new MailMessage();
myMail.From = "from@microsoft.com";
myMail.To = "to@microsoft.com";
myMail.Subject = "HTML Message";
myMail.BodyFormat = MailFormat.Html;
myMail.Body = reader.ReadToEnd(); // Load the content from your file...
//...
}