用于 ASP.NET 服务器的 Word 邮件合并

发布于 2024-09-18 05:25:56 字数 253 浏览 0 评论 0原文

需要为 ASP.NET 应用程序进行邮件合并。

考虑只是以编程方式直接使用 word,但这具有许可含义,不建议这样做 (http://support.microsoft. com/kb/257757

因此我们正在研究 openXML / Word 自动化服务。但不确定是否可以通过此轻松实现邮件合并?

Need to do a mail merge for ASP.NET application.

Considered just programatically using word directly but this has liscening implications and is not recommended (http://support.microsoft.com/kb/257757)

So was looking into openXML / Word Automation Services. But not sure if can easily achieve a mail merge via this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑脸一如从前 2024-09-25 05:25:56

4-5 年前我们就有这样的需求,然后我们决定采用定制的自制解决方案。以下是可能对您有所帮助的解决方案概要:

  1. 使用富文本框捕获邮件模板(用户可以创建自己的邮件)。使用特殊语法在模板中插入数据的占位符。所以你所拥有的是一个包含占位符的 html 正文。
  2. 当需要为N条记录生成邮件时,对于每条记录,解析模板html以搜索占位符(可以使用reg-ex完成)并用相关数据替换它们。
  3. 生成的 html 可以通过电子邮件发送(或者可以使用库将其转换为 pdf 或 word)。

实际上,这可能意味着根据实际需求进行大量工作。例如,在我们的案例中,

  1. 我们有一个元数据存储库,用于描述业务实体及其属性
  2. GUI,供最终用户定义模板。 UI 允许多部分模板(例如,如果您需要发送带有附件的求职信)、插入各种占位符(我们支持字段、实体组、简单过滤等)、部分格式(html/pdf/doc)、详细信息电子邮件/传真收件人(就元数据而言)
  3. 实体分组支持-本质上意味着具有子数据的能力。例如,要打印有关订单的信件,您必须为订单中订购的项目(产品)放置一个表格。可以有任何级别的此类嵌套。
  4. 为了提高效率,运行时只解析模板内容一次,然后只进行替换。我们还有查询引擎,可将元数据占位符转换为查询以获取数据等。

如果有任何预构建的工具用于此类事情,那就太好了,但因此我不知道任何事情。

编辑:如果您的要求是拥有用户定义的邮件模板,则上述所有内容都是相关的。如果您只有预定义的模板集,那么解决方案可能会简单得多 - 例如,(正如 Yves 指出的)使用带有数据绑定表达式的 aspx 文件来获取 html/xml 正文,然后将其转换为相关格式。然后,您可以使用 HttpServerUtility.Execute 来捕获任意数量记录的页面输出。

We had such requirement 4-5 years back and then we decided to go with custom self-made solution. Here's the outline of solution that may help you:

  1. Use rich text box to capture mail template (users can create their own mails). Use special syntax to insert placeholders for your data within the template. So what you have is a html body containing placeholders.
  2. When mails needs to be generated for N records, for each record, parse the template html to search for placeholders (can be done using reg-ex) and replace them with relevant data.
  3. Generated html can be emailed (or it can be converted into pdf or word using libraries)

In reality, this may mean a lot of work based on actual requirements. For example, in our case

  1. We have a metadata repository that describes business entities and their attributes
  2. GUI for end users to define the template. UI allows multi-part templates (e.g. if you need to send covering letter with attachments), insertion of various placeholders (we support fields, entity groups, simple filtering etc), format for a part (html/pdf/doc), details about email/fax recipients (in terms of metadata)
  3. Entity Grouping Support - means essentially that ability have child data. For example, for printing letter about an order, you have to put a table for items (products) ordered within an order. There can be any level of such nesting.
  4. To be efficient, there is runtime that parse template contents only once and then only do substitution. We also have query engine that converts metadata placeholders into a query to fetch data etc

It would be great if there is any pre-built tool for such thing but as such I am not aware of anything.

EDIT: All above is relevant if your requirements is to have user defined mail templates. If you have only predefined set of templates then solution can be a lot simpler - for example, (as Yves pointed out) using aspx files with data binding expressions to get the html/xml body and then convert it into relevant format. You can then use HttpServerUtility.Execute to capture page output for any number of records.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文