SMTP Adapter: Attachment Filename : Custom Pipeline
October 29, 2009 Leave a comment
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:
- In your pipeline project, reference Microsoft.BizTalk.GlobalPropertySchemas (C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.GlobalPropertySchemas.dll)
- Declare a static variable in your custom pipeline component that references the
MIME.FileNameproperty: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.
- 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));
wherepInMsg 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. - Once this message hits the SMTP adapter, it will attach the message with the name you specified in
fileNameas long as you’ve specified the Attachment Settings correctly.