SMTP Adapter: Attachment Filename : Custom Pipeline

When using the SMTP adapter, you need to do some special tinkering if you want to ensure that you attached message part has a sensible name.

Other blog posts cover how to do this from an orchestration but if you want to, say, receive a message from a file location sending it directly to the SMTP adapter with a name other than “body.dat” (or similar) you’ll need a pipeline component.

Here are some snippets:

  1. In your pipeline project, reference Microsoft.BizTalk.GlobalPropertySchemas (C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.GlobalPropertySchemas.dll)
  2. Declare a static variable in your custom pipeline component that references the MIME.FileName property:
    private static Microsoft.XLANGs.BaseTypes.PropertyBase attachmentFileNameProperty = new MIME.FileName();

    This makes life slightly easier – you won’t have to look up any namespaces or property names. You can also do this for loads of other properties including your own.

  3. On your message, you’ll need to set PartPropeties (rather than the message Context properties)So it’s something like this:
    pInMsg.BodyPart.PartProperties.Write(attachmentFileNameProperty.QName.Name, attachmentFileNameProperty.QName.Namespace, Path.GetFileName(fileName));

    where

    pInMsg is the message you are using in the pipeline
    PartProperties is the a collection of context properties for the message part
    fileName is the new name you want from the file, maybe determined from the received file name if you're using the file adapter.

  4. Once this message hits the SMTP adapter, it will attach the message with the name you specified in fileName as long as you’ve specified the Attachment Settings correctly.
Follow

Get every new post delivered to your Inbox.