如何使用HTML文件设置MailMessage的正文?
谢谢
解决方法
只需将
MailMessage.BodyFormat属性设置为
MailFormat.Html,然后将您的html文件的内容转储到
MailMessage.Body属性:
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... //... }