You are on page 1of 6

C:\Program Files\BizTalk

Utilities\Samples\BTSUtils.Adapters.POP3.MultiPartMessage\Input\Test Message.eml

The sample message can be opened using Microsoft Outlook Express.

Multipart Message Handling using the POP3 and


SMTP Adapters

Overview
Both the POP3 and SMTP Receive Adapter included within BizTalk Utilities provide a
processing model called Multipart.

When an email message is received by any of these Adapters, the email message body and
all of its attachments are submitted as a single message to BizTalk Server. If the body exists
within the email it will be submitted as the main message part and all of the attachments as
parts of the BizTalk message.

The attachment message parts will be named according to the file names provided within the
email message.

It is important to note that the message body and attachments will be submitted in their raw
format to BizTalk Server. For instance, if the email message contains a Microsoft Word
document, the document will be submitted as a Word document to BizTalk Server.

Attempting to process these types of messages within an Orchestration can be quite


cumbersome. The aim of this document is to provide a detailed step by step guide on how to
handle these types of messages within an Orchestration.
The Orchestration will then retrieve every part of the message and save them to a file
The Sample Orchestration location. The Orchestration can be extended to for instance read the contents of the
attachments and populate elements within an Xml document with the attachment data in a
The complete sample can be found within the Sample solution accessible from Start/All Base64 encoded format.
Programs/BizTalk Utilities/Samples.
In this example we will use a Publish-Subscribe model to activate the Orchestration; this
The project is called BTSUtils.Adapters.POP3.MultiPartMessage within the solution. means that the Orchestration will not be directly bound to the POP3 Receive Location. The
POP3 Adapter will simply submit the message to BizTalk Server and the subscribed
The Orchestration will receive an Email Message from the POP3 Adapter. The Email Orchestration will be activated according to a filter expression defined within the activation
Message contains a main body and two attachments. The first attachment is an HTML page receive shape of the Orchestration.
and the second is a Microsoft Word document. The Sample Message can be found at
The Orchestration Receive Email Message
This receive shape activates the Orchestration, because the Port is a Direct port we need
some type of filtering mechanism to filter the messages that the orchestration wants to
process. When we look at the Filter Expression for the Receive Shape we will see the
following

Orchestration References
The Orchestration references the BTSUtils.Mail.Schemas.Properties project contained within
the same solution in order to use the Mail Property Schemas.

It also references an assembly called BTSUtils.XLANGs.Components. The assembly contains


a set of utility classes that can be used within Orchestrations.
The BTSUtils.Mail.Scheams.Properties.Mailheader.from property contains the email from
ReceivePort Port which the message originated. The property is usually populated as follows “Pieter”
This port is responsible for receiving the email message from BizTalk Server. The receive port <from@2003-server>, we need to escape the quotes around Pieter and enter the expression
binding is set to Direct, which allows the Orchestration to subscribe to the Message Box as follows "\"Pieter\" <from@2003-server>".
database instead of being bound directly to the POP3 Receive Port.
Please note that you will probably have to change this filter expression if you are running on
another POP3 Server, since the email address will be different.
Other expressions can also be entered according to the different Mail Schema Properties Retrieve Body
available. Also remember that the Mail Schema can be extended to your specific needs. The Message Assignment Shape is responsible for extracting the Message Body. It contains
the following expression.
The message being received is called EMailMessage; this has a Multipart Message Type of
type MultiPartMessage.EmailMultipartType. When we look at this Multipart Message Type we BodyPartMessage = new
will see the following. BTSUtils.XLANGs.Components.Formatters.Stream(EMailMessage.Body);

The Expression simply assigns a new Stream object which takes the Body part of the Email
Message.

The Retrieve Attachment 1 and Retrieve Attachment 2 Shapes are exactly the same except
they retrieve the Attachment1 and Attachment2 parts and assign them to the
Attachment1Message and Attachment2Message messages.

Send Body
This Send Shape is responsible for sending the Body Part of the Email Message to the
BodyPort Port.

BodyPort
The EmailMultipartType contains 3 parts namely Body, Attachment1and Attachment2. This is The port is responsible for sending the BodyMessage to the following file location
exactly the same as our email message. If more attachments need to be processed the type
can be extended to have more parts. C:\Program Files\BizTalk
Utilities\Samples\BTSUtils.Adapters.POP3.MultiPartMessage\Output\Body_%MessageId%.ou
One strange thing that you will notice is that these part types are set to t
System.Xml.XmlDocumnet. We are not processing Xml data here though. The Body is Text,
Attachment1 is an HTML document and Attachment2 is a Word document. For some reasons Attachment1Port and Attachment2Port do exactly the same except that they will use a
this seems to work though, so we will not delve deeper on this topic. different filename as to not overwrite the Body Message.

Extract Parts
Configuring the POP3 Receive Location
This Construct Message shape is responsible for extracting the various parts of the email
message from the EmailMessage Multipart Message. It constructs 3 messages namely In this section we will configure the POP3 Receive Location.
BodyMessage, Attachment1Message and Attachment2Message. All of these messages have
a Message Type of BTSUtils.XLANGs.Components.Formatters.Stream. 1. Create a new Receive Port called POP3 Receive Port.

BTSUtils.XLANGs.Components.Formatters.Stream is a custom message type that allows us


to extract the message part as a stream from the Multipart Message. As an alternative you
can use BTSUtils.XLANGs.Components.Formatters.String to retrieve the Message Parts as
string values. This will obviously work for thing like Text Files and the Message Body, but not
for Microsoft Word Documents.
2. Underneath the Receive Port you create a new Receive Location call POP3 Receive 3. Configure the Address Property. In this example we will be polling an email account
Location. Select the BizTalk Utilities Adapter for POP3 Transport as the Transport Type. called 2003-server\to on a POP3 Server called 2003-server. We will be polling the email
Select you BizTalk Server Host as the Receive Handler. Select the Pass-through account every 5 minutes. Please note that the Processing property is set to Multipart.
Pipeline Component as the Receive Pipeline.
5. You must enable the Receive Location.

Deploying the Orchestration


The BTSUtils.Adapters.POP3.MultiPartMessage project is dependent on the mail schema
property schemas contained within the BTSUtils.Mail.Schemas.Properties project.

You will have to deploy BTSUtils.Mail.Schemas.Properties as well as


4. Our completed Receive Location will look as follows. BTSUtils.Adapters.POP3.MultiPartMessage.

Once deployed you can start the BTSUtils.Adapters.POP3.MultiPartMessage.Process


Orchestration.
Running the Sample
The sample can be run by forwarding the Test Message to the email account that the POP3
Receive Function is set to retrieve messages from.

The POP3 Receive Port will pick up the message at the specified interval. All Message Parts
will be written to the

C:\Program Files\BizTalk
Utilities\Samples\BTSUtils.Adapters.POP3.MultiPartMessage\Output

folder once the orchestration executes.

You might also like