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

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

问题描述

在BT2006R2中,我有一个业务流程,该流程接收具有电子邮件属性的XML,例如:to,cc,subject,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

我希望业务流程使用带有HTML电子邮件正文和1..n pdf文件作为附件的SMTP适配器发送1封电子邮件.

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 Restropo的博客帖子中对此进行了很好的演示.

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转换管道组件

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:\\Attachments\MyFile.pdf|C:\\Attachments\AnotherFile.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(甚至将它们作为消息部分添加到另一条消息中)
  • 某种自定义适配器解决方案-可能对您所需要的功能造成了极大的破坏.
  • Static list of files you will receive each going to a receive location - not so good for you since it sounds like the PDF files can change
  • Master orchestration that reads your control file and then "orchestrates" the behaviour of child orchestrations
  • Code based solution - a C# class that takes your list of files and returns them to BizTalk as messages (or even adds them as message parts to another message)
  • Some sort of custom adapter solution - probably huge overkill for what you need.

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

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