我有一个项目要求,我们需要将 HTML 格式的日志表附加到发送给用户的电子邮件中。 我不希望日志表成为正文的一部分。我不想使用 HTMLTextWriter 或 StringBuilder,因为日志表非常复杂。
是否有另一种我没有提到的方法或可以使这变得更容易的工具?
注意:我已经使用 MailDefinition 类并创建了一个模板,但我还没有找到一种方法将其作为附件(如果可能的话)。
I have a project requirement that we need to attach an HTML formatted log sheet to an email that gets sent to a user. I don't want the log sheet to be part of the body. I'd rather not use HTMLTextWriter or StringBuilder because the log sheet is quite complex.
Is there another method that I'm not mentioning or a tool that would make this easier?
Note: I've worked with the MailDefinition class and created a template but I haven't found a way to make this an attachment if that's even possible.
发布评论
评论(2)
由于您使用的是 WebForms,我建议 渲染您的日志表在控件中作为字符串,然后将其附加到 MailMessage。
渲染部分看起来有点像这样:
如果您有可编辑控件(
TextBox
、DropDownList
等),则需要在调用之前将它们替换为标签或文字GetRenderedHtml()
。请参阅 这篇博文是一个完整的例子。这是MSDN 附件示例 :
Since you're using WebForms, I would recommend rendering your log sheet in a Control as a string, and then attaching that to a MailMessage.
The rendering part would look a bit like this:
If you have editable controls (
TextBox
,DropDownList
, etc), you'll need to replace them with Labels or Literals before callingGetRenderedHtml()
. See this blog post for a complete example.Here's the MSDN example for attachments:
您可以使用 Razor 作为电子邮件模板。 RazorEngine 或 MvcMailer 可能会为您完成这项工作
在 Web 表单应用程序中使用 Razor 视图作为电子邮件模板< /a>
Razor 视图作为电子邮件模板
http://www.codeproject.com/文章/145629/宣布-MvcMailer-使用-ASP-NET-MVC 发送电子邮件
http://kazimanzurrashid.com/posts/使用-razor-for-email-template-outside-asp-dot-net-mvc
You can use Razor for email templates. RazorEngine or MvcMailer might do the job for you
Use Razor views as email templates inside a Web Forms app
Razor views as email templates
http://www.codeproject.com/Articles/145629/Announcing-MvcMailer-Send-Emails-Using-ASP-NET-MVC
http://kazimanzurrashid.com/posts/use-razor-for-email-template-outside-asp-dot-net-mvc