加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

发送带有HTML文件的电子邮件(C#)

发布时间:2020-12-14 21:29:36 所属栏目:资源 来源:网络整理
导读:如何使用HTML文件设置MailMessage的正文? 谢谢 解决方法 只需将 MailMessage.BodyFormat属性设置为 MailFormat.Html,然后将您的html文件的内容转储到 MailMessage.Body属性: using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your
如何使用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...
    //...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读