Description: This sample shows how to receive an email via the POP3 Adapter and break off unlimited attachments as separate messages. Each message will be saved to a folder location. Note that this sample is not fully functional; you need to set up the POP3 Receive Location yourself to an existing email address.

Download: Splitting Out POP3 EMail Attachments Sample

Author: Stephen W. Thomas

Related Items: Suspended Message Routing and Error Reporting Sample, Calling a Receive Pipeline Inside an Orchestration Sample

Acumen Businesss

Original Blog Posting:

Splitting POP3 Email Attachments in BizTalk 2006

Posted on Tuesday, August 08, 2006 9:39 PM

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.

posted on 2007-04-15 18:55  失落  阅读(198)  评论(0编辑  收藏  举报