Skip to content

Accept Email attachments via BizTalk

February 20, 2013

Email is in some ways appealing as a transport for automated and semi-automated data transfer between unrelated parties.

  • Its store-and-forward nature overcomes temporary outages
  • Many businesses are equipped to automatically generate and/or accept data via emailed files
  • Individuals and other small business partners can manually create and receive emails with attached files

However, there are complications. Email systems do not all follow a single, comprehensive standard for message structure.


  • There is usually a MIME message part for the email’s “body text”, even if the email is system-generated and only exists to bear an attached file
  • The Body text may be part #0, or it may not
  • The Body text may have a filename attribute which is blank, or it may not have a filename attribute at all
  • Emails submitted by humans may have backgrounds or company logos also as MIME parts, with or without file names
  • Attachments may have their filename described in a message “content-disposition” header, though sometimes not.


Biztalk Email Attachment Handling



SinglePart –System.Xml.XmlDocument

In — System.Xml.XmlDocument


oXMessage — System.Xml.XmlDocument

nCount — System.Int32

n — System.Int32, initial value=0


Receive intoIn 


oXMessage = In;
nCount = oXMessage.Count;

Loop: n<nCount {

Construct: SinglePart = oXMessage[n];


if (MIME.FileName exists CSV_Out) 
else if (MIME.PartContentTypeSecondaryHeaderValue exists CSV_Out) 

Rule:  tests on filename, e.g. 

(fileName.EndsWith(".CSV", System.StringComparison.CurrentCultureIgnoreCase))

Send or process the file

n = n + 1;



If you need the original filename assigned to another promoted field of the message, you’ll need to construct another message, as:

  1. The exists test won’t work on the original multi-part message, nor on indexed parts of the variable; only after the individual message is created
  2. If / else cannot be used within a Construct Message shape
  3. Distinguished fields can only be set within a Construct Message shape


I’m not a BizTalk guru. If I’m wrong, or if you have a more concise/complete example, please let me know.


From → IT

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: