[INACTIVE BLOG] Connected Thoughts – Thiago Almeida

August 12, 2009

Receiving MIME encoded email files and a hidden POP3 context property

Filed under: BizTalk — Thiago Almeida @ 11:28 pm


Now that POP3 is not a part of Windows Server 2008 it is probably timely to post on a hidden POP3 adapter context property that you can use to decode emails picked up from the file system without actually using the POP3 adapter. I’ve been meaning to blog this for a while since I investigated it when reviewing a question on the MSDN forums. This trick is also useful for when you are using the POP3 Adapter but need to store the original email before any MIME decoding and then need to apply the decoding to it (in this case set the ‘Apply MIME decoding’ property on the POP3 adapter to false then use the method below later).

The POP3 adapter handles the POP3 protocol negotiation over TCP/IP to retrieve MIME encoded email messages. Once it has the email content, it puts it internally through an instance of the MIME/SMIME pipeline component (which in turn uses the COM dll BTSMIMEComps.dll) to decode it, and from there the message is given to the receive location pipeline.

The adapter writes (not promotes) an undocumented context property called CopyMailHeadersToContext to the message context before passing it to the MIME/SMIME pipeline component – this tells the component to add some POP3 properties to the message context as well.

So if you have MIME encoded emails being forwarded to BizTalk via file, FTP or otherwise (usually files with a .eml extension), you can reproduce the adapter’s behaviour by creating a very simple pipeline component to write the CopyMailHeadersToContext property with the POP3 adapter namespace and a value of 3 (don’t ask me why 3, still not sure about this value), then place it just before the MIME/SMIME pipeline component in the decode stage of a receive pipeline:


This is the execute method of the pipeline component, almost as simple as it gets:

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
   //By writing this to the context we tell the MIME/SMIME decoder to
   //populate the POP3 context properties while going through the email message
   "http://schemas.microsoft.com/BizTalk/2003/pop3-properties", 3);
   return pInMsg;


Once the message goes through this pipeline you will then get some valuable properties in the context that you wouldn’t see with just the MIME/SMIME component. The properties are Date, From, Headers, Subject, and To:


And that’s it, pretty simple really :).

Download the sample here (Visual Studio 2008, BizTalk 2009)


Thiago Almeida



  1. Whow,

    This is actually very cool. We use Mail for our incoming edi messages. Not having to use POP3 (with the concurrency problems if you have multiple receive hosts) is a real solution for us.

    Now we can just route the incoming mails with the smtp protocol to a file location.

    This saves us a lot of work !

    Comment by Patrick Wellink — August 20, 2009 @ 10:35 pm

  2. Hey Thiago,

    Long time!

    Is there a way to pass the message context (when using the pop3 adapter in my case) to a .net component? I want to retrieve the from,cc etc field in the .net component to form an xmldocument.


    Comment by Dipesh Avlani — December 17, 2009 @ 10:18 am

    • Hi Dipesh, you would have to:
      – Get the values from the context inside a custom pipeline component or
      – Get the values from the context inside an orchestration and pass the values
      – Pass the entire BizTalk message to your .NET component (IBaseMessage in the pipeline component, XLangMessage in the orchestration) and get the values from the context in your .NET code

      Comment by Thiago Almeida — January 27, 2010 @ 7:14 am

  3. how can i promote the message context properties of pop3 ? i would have to do the promotion after xml dissassembler ? and what will be the value of field in the argument object of pInMsg.Context.Promote( ,,Object) ?

    Comment by guneet kalra — February 15, 2013 @ 8:37 pm

  4. hi Thaigo

    how did you promoted the subject property ? Please help

    Comment by guneet kalra — February 18, 2013 @ 8:32 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Create a free website or blog at WordPress.com.

%d bloggers like this: