tags:

views:

901

answers:

1

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

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

How can this be done ?

+3  A: 

You are really asking three seperate questions here.

  1. How to send an HTML email in BizTalk.
  2. How to add attachments to an email in BizTalk.
  3. How to dynamically read in files to a BizTalk process.

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.

How to send an HTML email in BizTalk

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

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.

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).

How to add attachments to email in BizTalk

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

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.

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.

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

How to dynamically read in files to a BizTalk process

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

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

You have a few options:

  • 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.
David Hall
Hi David, whow you did some homework here ;-) Thanks a lot. I already did some more reading on the internet and I have a nice working solution now by using the rawstring for the html body and dynamically adding attachments with a helper class (as parts).
Patrick Peters
@Patrick good to hear that you have this working. Some of these 'simple' things in BT like sending a nicely formatted email with attachments can be really hard to get going - it's almost like the basic tooling keeps getting bumped for the advanced features.
David Hall