问题
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 ?
回答1:
You are really asking three seperate questions here.
- How to send an HTML email in BizTalk.
- How to add attachments to an email in BizTalk.
- 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.
来源:https://stackoverflow.com/questions/2187750/send-html-email-in-biztalk-with-multiple-pdf-attachments-with-smtp-adapter