发送带有HTML文件作为正文的电子邮件(C#) [英] Send an email with a HTML file as body (C#)
本文介绍了发送带有HTML文件作为正文的电子邮件(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用HTML文件设置MailMessage的正文?
How can I set the MailMessage's body with a HTML file ?
推荐答案
只需设置 MailFormat.Html ,然后将html文件的内容转储到
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...
//...
}
这篇关于发送带有HTML文件作为正文的电子邮件(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文