使用 SMTP 适配器在 BizTalk 中发送带有多个 pdf 附件的 HTML 电子邮件 [英] Send HTML email in BizTalk with multiple pdf attachments with SMTP adapter

查看:75
本文介绍了使用 SMTP 适配器在 BizTalk 中发送带有多个 pdf 附件的 HTML 电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 BT2006R2 中,我有一个编排,它接收带有电子邮件属性的 XML,例如:收件人、抄送、主题、htmlbody 的文件位置、带有 pdf 文件的 1..n 文件位置

In BT2006R2 I have an orchestration which receives an XML with email properties like: to, cc, subject, filelocation for htmlbody, 1..n filelocations with pdf files

我希望编排使用 SMTP 适配器发送 1 封电子邮件,其中 HTML 电子邮件正文和 1..n 个 pdf 文件作为附件.

I want the orchestration to send 1 email with the SMTP adapter with the HTML emailbody and 1..n pdf files as attachments.

如何做到这一点?

推荐答案

你真的在这里问了三个单独的问题.

You are really asking three seperate questions here.

  1. 如何在 BizTalk 中发送 HTML 电子邮件.
  2. 如何在 BizTalk 中向电子邮件添加附件.
  3. 如何将文件动态读入 BizTalk 进程.

我在下面逐一介绍 - 问题 2 最简单的解决方案实际上避免了处理问题 3.

I address each below - the most simple solution to issue 2 actually avoids having to deal with issue 3.

希望这将使您走上解决此问题的正确轨道.遗憾的是,它太宽泛了,以至于我无法给出一个单一的这就是你的答案",但如果你遇到问题,请回来发布更多问题.

Hopefully this will get you on the right track for solving this. Sadly, it is so broad that I can't give a single "this is how you do it answer", but if you hit snags, come back and post more questions.

如何在 BizTalk 中发送 HTML 电子邮件

我知道有两种方法可以实现这一点.

There are two methods that I know of to achieve this.

一种是使用 RawString 类并将其直接分配给您的电子邮件正文.这篇 Tomas Retropo 的博文很好地证明了这一点.

One is to use the RawString class and assign this directly to your email body. It is well demonstrated in this blog post by Tomas Restropo.

第二种方法是使用XSLT Transform Pipeline 组件详解在 MSDN 上.这允许您指定将普通测试消息正文转换为 HTML 正文的 XSLT 模板.

The second method is to use the XSLT Transform Pipeline component detailed here on MSDN. This works by allowing you to specify XSLT templates that will transform your plain test message body into an HTML body.

我过去使用过这两种方法.每个都有其优点和缺点.模板方法的一个很好的特点是它在运行时可配置性稍强(但如果您设计得很好,则只有一点).

I've used both approaches in the past. Each has its strengths and weaknesses. One nice feature of the template method is that it is slightly more runtime configurable (but only slightly if you design the other way well).

如何在 BizTalk 中向电子邮件添加附件

同样,在 BizTalk 中有两种主要的实现方法.

Again, there are two main methods of achieving this in BizTalk.

第一种方法是使用 SMTP.Attachments 上下文属性.在您的业务流程中的消息分配表达式形状中,您有如下代码:

The first method is to use the SMTP.Attachments context property. In a message assignment expression shape within you orchestration you have code like below:

MessageOut(SMTP.Attachments) = 
    "C:\AttachmentsMyFile.pdf|C:\AttachmentsAnotherFile.pdf";

您只需添加一个文件列表,其中文件路径用竖线分隔.

You simply add a list of files, where the file paths are pipe delimited.

这可能非常符合您的要求 - 这是向电子邮件动态添加附件的最简单方法,并且无需将文件实际加载到 BizTalk 中.

This could be a good match for your requirement - it is the easiest way of dynamically adding attachments to an email, and avoids needing to actually load the files into BizTalk.

此外,上面的表达式形状是简单的代码,因此您可以根据需要使上面的内容动态化.

Also, the above expression shape is simply code so you can make the above as dynamic as you need.

另一种方法是从 BizTalk 发送多部分消息.根据上下文设置,您可以将所有邮件部分作为附件发送,或将第一部分用作邮件正文.

The other method is to send a multipart message from BizTalk. Depending on context settings you can send all message parts as attachments, or use the first part as the message body.

创建多部分消息有点复杂,所以我不会深入讨论 - 通常您需要一个帮助类来将部分添加到您的消息中.

Creating a multipart message is a little involved so I won't go into it - generally you will need a helper class that adds parts to your message.

上下文属性(在消息分配形状中设置)是:

The context properties (set in a message assignment shape) are:

MessageOut(SMTP.MessagePartsAttachments) = n

// Where n can be one of three values
0 (same as not set) - Do not attach any biztalk message parts. This is a default setting.
1 - Attach only biztalk body part
2 - Attach all parts

如何将文件动态读入 BizTalk 进程

这又涉及到很多,所以我不会详细介绍.还有其他 SO 问题可以解决这个问题.

This again is quite involved so I won't go into great detail. There are other SO questions that address this.

基本上,如果您使用多部分消息,则需要以某种方式将每个消息部分放入 BizTalk.

Essentially, if you are using multipart messages, you will need to get each message part into BizTalk somehow.

你有几个选择:

  • 您将收到的文件的静态列表,每个文件都将发送到接收位置 - 对您不利,因为听起来 PDF 文件可能会发生变化
  • 主编排读取您的控制文件,然后编排"子编排的行为
  • 基于代码的解决方案 - 一个 C# 类,它获取您的文件列表并将它们作为消息返回给 BizTalk(或者甚至将它们作为消息部分添加到另一条消息中)
  • 某种自定义适配器解决方案 - 对于您需要的东西来说可能是巨大的矫枉过正.

这篇关于使用 SMTP 适配器在 BizTalk 中发送带有多个 pdf 附件的 HTML 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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