Tuesday, January 31, 2006

BizTalk 2006 POP3 Adapter

There are a few things that I've learned recently while using the latest BizTalk 2006 beta. I'll start by listing a few things that might help someone who is using the new POP3 Adapter. This information was gathered from other web pages, news groups, and my own experience.

Using the POP3 adapter to receive a message where the XML attachment is all that you care about is about as easy as using any other adapter. I've seen information about this in other places, so I won't copy it here.

To use the POP3 adapter to receive an email with attachments in an orchestration (where the number of attachments is fixed and known) and you intend to have access to all parts of the email:
  1. Create a multipart type in the orchestration, one part for the email body and one for each attachment.
  2. Make each part of the multipart type an XmlDocument, even if the body of the message is not XML. I've seen articles that make me think it might be important for the body part of the multipart type to be created first, although I haven't tested it any other way.
  3. Since Visual Studio will sort the parts of the multipart type by name (although the actual order of the parts in the ODX file is unaffected), I recommend naming the parts something that will maintain the same order, for example "BodyPart" and "Remainder1", "Remainder2", etc.
  4. In the orchestration, to use any of the incoming parts that are XML, you can simply assign that body part to your message (it took me a while to discover that [for my purposes, anyway] XmlDocument is assignment compatible with any message that is of an XML schema type).
When I first tried receiving a POP3 message in an orchestration, I received the following error message:
Multi-part message 'EmailIn' has body part '{AE9F5DD0-CE12-49C3-B9B3-577D3B134EBB}', expected body part '{3FB96D26-27B3-44A1-9606-CFBEA88A668D}.
When I created the receive port, I had left the body part index set to 0 in the receive location. My thinking was that since I wasn't going to select just a part of the message, I could leave it at the default. Well, my thinking was wrong -- the error went away when I changed the body part index to 1, and I was able to receive the email in the orchestration.

2/9/2006 - There's more on the POP3 adapter from Richard Seroter here.