]> BizTalk MIME Content-Disposition 🌐:aligrant.com

BizTalk MIME Content-Disposition

Alastair Grant | Wednesday 10 January 2018

I have been trying to handle inbound emails from end users in BizTalk but have fallen down at the final hurdle: the inconsistent approach to MIME encoding.

BizTalk will provide MIME decoding, either through the S/MIME decode Pipeline Component, or possibly on the Adapter that you're using (e.g. POP3).  This will create a multi-part message in BizTalk, with each part corresponding to a MIME part in the original email.

You can then loop through these parts and get various MIME related contextual properties.

foreach(XLANGPart part in msg) {
  string filename = part.GetPartProperty(typeof(MIME.FileName));

The problem is, in this day and age of filling your email up with company logos and social media icons, is that people are making much more use of embedded images in email.

My particular requirement involved being able to separate the real attachments from the inline attachments.  Whether something is inline or not is defined by the Content-Disposition, e.g.:

Content-Disposition: inline
Content-Disposition: attachment; filename="whatever.jpg"

BizTalk reads this property and extracts the filename correctly and enters it into the MIME.FileName property.  Unfortunately it does not do anything with the attachment or inline bit, which means that information is inaccessible.

I tried using Content-ID, which is used to link internally to embedded resources in an email.  There is no need for a content-id being specified if it's just an attachment.  And whilst many email clients work like this, it turns out, some do not and also include the content-id when it's not required.

So I have hit a brick wall with MIME support in BizTalk.  Where to next?

Unfortunately the next step is to roll your own MIME decoding support.  MIME is a bit of an inconsistent nightmare, so that's probably not something you want to do.  Fortunately for us, MimeKit exists, which is an open-source C# project for handling of MIME.  This can be used in a custom pipeline component to decode instead.

You will need to write the relevant properties into the MIME.* schemas and also write any other information, such as disposition into a property schema of your own.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.