如何将电子邮件页面/模板的内容提取到 .NET 中的 MailMessage 正文中
我有一个电子邮件模板,它只是一个普通的静态 HTML 页面。
我需要将该页面放入 MailMessage
的正文中。
通常我要做的只是创建一个 StringBuilder 并一遍又一遍地附加这些行。但这是一个很长的页面,我不想用单引号等替换引号。
那么有没有一种方法可以将 html 页面的内容拉入字符串中?如:
emailMessage.IsBodyHtml = true;
emailMessage.Subject = "Test Subject";
emailMessage.Body = GetContentsFrom("emailtemplate.html");
谢谢!
I have an e-mail template which is just a plain, static HTML page.
I need to get that page into the Body of a MailMessage
.
Normally what I would do is just create a StringBuilder
and append the lines over and over. But it's kind of a long page, and I don't want to go through replacing the quotes with single quotes etc..
So is there a way to just pull in the contents of an html page into a string? Such as:
emailMessage.IsBodyHtml = true;
emailMessage.Subject = "Test Subject";
emailMessage.Body = GetContentsFrom("emailtemplate.html");
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 GetContentsFrom 替换为 File.ReadAllText 吗?
Could you replace GetContentsFrom with File.ReadAllText?
我认为这个例程可以解决问题:
I think this routine would do the trick:
该页面是否托管在某处?你可以这样做:
private string HtmlPageInToString()
{
}
Is the page being hosted somewhere? You could do this:
private string HtmlPageInToString()
{
}