我可以建立HTML /电子邮件模板使用ASP.NET? [英] Can I set up HTML/Email Templates with ASP.NET?

查看:494
本文介绍了我可以建立HTML /电子邮件模板使用ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个网站,将发送电子邮件的数量显著。我想设置标题和页脚文本,或者甚至模板,以允许,如果他们需要的用户方便地编辑这些电子邮件。

I'm working on a site that will send out a significant number of emails. I want to set up both header and footer text, or maybe even templates to allow the users to easily edit these emails if they need to.

如果我嵌入的C#字符串里的HTML,它的丑陋,他们将不得不担心逃跑。包括页眉和页脚可能工作平面文件,但一些关于它只是感觉不对。

If I embed the HTML inside C# string literals, it's ugly and they would have to worry about escaping. Including flat files for the header and footer might work, but something about it just doesn't feel right.

什么是理想是什么以某种方式使用 .ASPX 页面为模板,然后就告诉我的code担任该页面,并使用HTML返回的电子邮件。

What would be ideal what be to use a .ASPX page as a template somehow, then just tell my code to serve that page, and use the HTML returned for the email.

有一个很好的和简单的方法来做到这一点?有没有更好的方法去解决这个问题?

Is there a nice and easy way to do this? Is there a better way to go about solving this problem?

更新:

我添加了一个答案,使您可以使用标准的.aspx页面作为电子邮件模板。只需更换所有的变量就像你通常会使用数据绑定,等于是刚刚捕获的页面,瞧的输出!你有你的HTML电子邮件!

Updated:
I added an answer that enables you to use a standard .aspx page as the email template. Just replace all the variables like you normally would, use databinding, etc. Then just capture the output of the page, and voila! You have your HTML email!

与CAVEAT已更新!

我使用了一些aspx页面的MailDefinition类就好了,但在尝试过程中正在运行服务器进程使用这个类的时候,它失败了。我相信这是因为MailDefinition.CreateMailMessage()方法需要一个有效的控制参考,尽管它并不总是做一些事情。正因为如此,我会建议使用一个aspx页面,或使用ASCX页面,这似乎更好一点门道的做法我的做法。

UPDATED WITH CAVEAT!!!:
I was using the MailDefinition class on some aspx pages just fine, but when trying to use this class during a server process that was running, it failed. I believe it was because the MailDefinition.CreateMailMessage() method requires a valid control to reference, even though it doesn't always do something. Because of this, I would recommend my approach using an aspx page, or Mun's approach using an ascx page, which seems a little better.

推荐答案

有一吨的答案已经在这里,但我偶然发现了有关如何使用剃刀与电子邮件模板一个伟大的文章。剃刀用ASP.NET 3推压,但MVC使用剃刀不是必需的。这是在做邮件模板的pretty圆滑处理

There's a ton of answers already here, but I stumbled upon a great article about how to use Razor with email templating. Razor was pushed with ASP.NET MVC 3, but MVC is not required to use Razor. This is pretty slick processing of doing email templates

正如文中指出,剃刀的最好的事情是,不像它的predecessor(web表单),它不与网络环境的束缚,我们可以很容易地承载它的网站外,并用它作为各种模板引擎目的。

As the article identifies, "The best thing of Razor is that unlike its predecessor(webforms) it is not tied with the web environment, we can easily host it outside the web and use it as template engine for various purpose. "

生成HTML电子邮件与RazorEngine - 01部分 - 引言

利用剃刀模板ASP.NET之外:他们不只是为HTML了

智慧的电子邮件模板与RazorEngine

类似的QA#1

使用新的API RazorEngine 模板

使用剃刀无需MVC

<一个href=\"http://stackoverflow.com/questions/3628895/is-it-possible-to-use-razor-view-engine-outside-asp-net\">Is有可能使用的Razor视图引擎之外asp.net

这篇关于我可以建立HTML /电子邮件模板使用ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆