【发布时间】:2018-02-23 13:29:13
【问题描述】:
我需要将 html 代码解析为字符串,因为我稍后会将其用作电子邮件的正文内容:
有没有办法像这样解析html代码:
<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>You have successfully subscribed!</p>
<hr>
<p class="mb-0">We will be sending you newsletter on weekly basis.</p>
</div>
以干净的方式进入字符串,而不是这样:
string body = @"<div class=""alert alert-success"" role=""alert"">" + "</div>"
所以我可以像这样将它传递给邮件:
MailMessage mailMessage = new MailMessage();
mailMessage.Body = body;
而不是在字符串中包含一整套 html 代码。
是否有任何其他“方式”可以为电子邮件进行“设计”?
PS:我也不想从外部文件加载html
我想使用 html 代码来设计一个体面的电子邮件订阅时事通讯消息。
谢谢!
【问题讨论】:
-
既然您希望它在电子邮件中,为什么不允许在您的电子邮件中包含 html 内容? stackoverflow.com/questions/8628683/…
-
不完全清楚你在这里问什么。在项目中将 html 文件作为嵌入式资源如何?还是希望用户输入html?
-
我希望我的 html 代码显示邮件的外观。例如,如果 id 在其中放置了一个按钮,则接收电子邮件的用户实际上可以单击该按钮并在@stephen.vakil 处重定向
标签: c# html asp.net-mvc email html-parsing