Receive EMails with Attachment and save the attached files under their original filename

Receiving EMails is possible using the pop3 adapter of Microsoft Biztalk Server 2006. But if you want to save multiple attachments with their original filename, you have to do a little detour with an orchestration.

Following process steps have to be defined:

  1. Create a new Biztalk Project with help of Visual Studio – Insert an new blank orchestration
  2. Definition of a unidirectional receive port with communication direction “I always receive messages on this port” and port binding “Define later”
  3. Definition of a unidirectional send port with communication direction “I always send messages on this port” and port binding “Define later”
  4. Definition of process and the variable nCount of type Int32 (Init value 1)
  5. Compile and provide the orchestration
  6. Create a receive port type POP3 with help of Biztalk Management Tool – Port Configuration with the credentials of you POP3 servers. Important is to set the option “MIME Decoding” to true
  7. Create a send port of type file (e.g.) with help of Biztalk Management Tool – Port Configuration. It is important using makro %SourceFileName%
  8. Activating ports, bind the ports to the orchestration
  9. Starting the orchestration

cc cc receive pop3 messages

Process step GetCount determine the amount of included attachments and save it to the variable nCount

//Set the input message to a var of XLang Message type
oXMessage = In;
// Get count
nCount = oXMessage.Count;

Process step MessageAssignment is called in a loop and transfers one attachment after the other to the send port. The original filename is transfered by MIME.FileName to the File.ReceivedFileName property of the send port, so that with help of the macro %SourceFileName% the original filename can be reused.

//Get the n'th part and set to a new message
Out = oXMessage[n];
Out(FILE.ReceivedFileName) = Out(MIME.FileName);
// Add to count
n = n + 1

Download of the Orchestration