Issue while implementing attachment extraction using Orchestration RRS feed

  • Question

  • I have a scenario where I will be getting attachment on mailbox. I need to extract that attachment for further processing. 

    I have implemented the looping of multi-part message referring(http://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/2006/08/08/how-to-split-received-email-attachments-in-biztalk-2006.aspx) but it is creating 4 files, one with attachment and others with email details. 

    Please help me to get only the attachment part ignoring the rest.

    One more thing I have found that while using gmail, it is creating only one attachment file as required but while using office365 it is creating 4 files.

    Below is the orchestration I have implemented using the above link. I need to access only the attachment of the mail.

    Please help me with this issue. I need to solve it on urgent basis.


    Tuesday, May 30, 2017 3:39 AM

All replies

  • IIRC you should have properties on each attachment telling you what to grab

    We have an older implementation with 3 attachments at times
    I can check it later

    rgds /Peter

    Tuesday, May 30, 2017 6:32 AM
  • Hi Peter,

    Thank you for your reply.

    I have only one attachment coming on mail.

    But after the orchestration executes, it is creating 4 files. 3 files are having garbage data and xml of email contents like subject, To, From etc. 4th file is the actual attachment. I need only this attachment file in my destination folder. As further processing is being done on attachment.




    Tuesday, May 30, 2017 10:05 AM
  • Check message type of each part and use a decide shape inside your loop shape "looppart"
    Send all parts you don't like to a garbage folder

    hth /Peter

    Tuesday, May 30, 2017 1:32 PM
  • Hi Divyani

    U can use a custom pipeline component so that perfomance of the solution would be better.

    Try out this link:-


    Wednesday, May 31, 2017 10:13 AM
  • Hi,

    I have implemented the pipeline component. The original code had some bugs and was creating 4 files(3 images and one attachment). After manipulating the code little bit now I am receiving only the csv file but it is a blank attachment. I am using BizTalk 2009 for the project.

    Below is my updated code:


            public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)

                var partName = string.Empty;

                // we start from index 1 because index zero contains the body of the message

                // which we are not interested

                for (int i = 1; i < inmsg.PartCount; i++)

                    IBaseMessagePart currentPart = inmsg.GetPartByIndex(i, out partName);

                    Stream currentPartStream = currentPart.GetOriginalDataStream();

                    var ms = new MemoryStream();

                    IBaseMessage outMsg;

                    outMsg = pc.GetMessageFactory().CreateMessage();

                    if (outMsg.Context == null)
                        outMsg.Context = pc.GetMessageFactory().CreateMessageContext();

                    outMsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);

                    if (outMsg.GetPart("Body").PartProperties == null)
                        outMsg.GetPart("Body").PartProperties = pc.GetMessageFactory().CreatePropertyBag();

                    for (int j = 0; j < inmsg.Context.CountProperties; j++)

                        string currentName;

                        string currentNamespace;

                        object objin = inmsg.Context.ReadAt(j, out currentName, out currentNamespace);

                        outMsg.Context.Write(currentName, currentNamespace, objin);

                        if (inmsg.Context.IsPromoted(currentName, currentNamespace))

                            outMsg.Context.Promote(currentName, currentNamespace, objin);



                    for (int j = 0; j < currentPart.PartProperties.CountProperties; j++)

                        string currentName;

                        string currentNamespace;

                        object objin = currentPart.PartProperties.ReadAt(j, out currentName, out currentNamespace);

                        outMsg.GetPart("Body").PartProperties.Write(currentName, currentNamespace, objin);


                    byte[] buffer = new byte[4096];
                    int bytesRead = 0;

                    while ((bytesRead = currentPartStream.Read(buffer, 0, buffer.Length)) != 0)
                        ms.Write(buffer, 0, bytesRead);
                    string attachmentContent = Encoding.Default.GetString(ms.ToArray());
                    MemoryStream attachmentStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(attachmentContent));

                    //string attachmentContent = Encoding.UTF8.GetString(ms.ToArray());
                    //MemoryStream attachmentStream = new System.IO.MemoryStream(
                    outMsg.GetPart("Body").Data = ms;

                    //Promote attachment file name

                    outMsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", currentPart.PartProperties.Read("FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties"));




    Please suggest any change to make it work.


    Thursday, June 1, 2017 10:33 AM