This was a question (paraphrased) on the BizTalkGurus.com Forum: “How can I take email attachments and put them as is into a folder?”

When using the POP3 Receive Adapter, you have the ability to receive multiple items as attachments and the adapter will handle them using MIME processing. You do not need a custom pipeline.

When receiving a multi-attachment message, you have the ability to define one of the parts as the main message Body. If you leave the default (0), the email message body will be the main message Body and all attachments will be additional parts to the message.

Lets say you have 3 attachments and you want to receive in an email and write them out to disk in a folder location (you can always publish them to the message box and do anything you want with the messages). You could probably use a custom pipeline to break out the multi-part message into separate messages…

I found a very simple and straight forward approach to accomplish this task. The Orchestration looks like this:

The key is to create an Orchestration variable of type Microsoft.XLANGs.BaseTypes.XLANGMessage. In order to do this, you need to add a reference to Microsoft.XLang.BaseTypes.dll. Once you have this variable, you just need to set it equal to your input message like: oXMessage = In.

You now have access to everything the XLangMessage has available; most importantly Count and access to all the message parts. Now a simple loop can be used to loop over the parts and create new output messages for each message part.

The output messages are created like: Out = oXMessage[n] were n is the message part index (starting at 1 since 0 is the Body). It’s that simple. It’s a total of 4 lines of code inside the Expression Shape and Message Construct.

I have a sample solution available for download below.

Download: Splitting POP3 Email Attachments in BizTalk Server 2006

See the readme.txt file for set up information.