I'm creating an email with a MIME attachment from a BizTalk 2016 SMTP Send Port. However, I think any knowledge that anyone can share from any other language about the oddities of Outlook and MIME might help me fix the issue below.
In Outlook, the attachment shows as body.txt, but when I click "File Save" it shows the name that I used when I created it (and that's what the user wants to see).
What I'm referring to is the the left side where it says "body.txt" above the 5k and to the right of the attachment icon in the screen shot below:
In BizTalk C# Pipeline component, that attachment was set with the following code, where we are setting Context properties on the BizTalk Message. I also tried setting ContentHeader and ContentID.
strFilename = "MyFileName_693.txt"; // Just for example.
pInMsg.BodyPart.PartProperties.Write(
"FileName",
"http://schemas.microsoft.com/BizTalk/2003/mime-properties",
strFilename);
When I forwarded the email to my Gmail, the attachment was shown with the proper name. So my question is particular to making it appear with the desired name in Outlook (2016).
So far I've got this working with an orchestration with a dynamic send port. It's still a bit of work, but it gets the job done with the stock component. Following description is based on the stock SMTP-adapter included in BizTalk 2013R2.
Note: even though my solution works, it feels like a workaround and something i shouldn't have to do, if the adapter was just slightly smarter about this.
First of all, let's look example email snippet which causes issues in some clients:
Notice the
Content-Description: body
part. This is the reason why some clients readbody.xml
or in my casebody.pdf
, even though the Disposition part looks great:Content-Disposition: attachment; filename="CDM_Order - Copy.pdf"
.Hard setting
MIME.FileName
isn't just going to work, even though it will set theContent-Disposition
right eventually, it'll never update theContent-Description
. This is because either on a static send port you've set theAttach only body part
or you specified the corresponding numeric value1
on a dynamic send port.However, it will work with the
Attach all parts
or2
value for the typeMessagePartsAttachments
. This involves making a multi-part message in your orchestration. This will have two parts;BodyPart
, now this one will include your message text and not your attachment. Make sure you specify this one asMessage Body Part
in theMessage Type
.Attachment
in this example.Now you might think it will send the
BodyPart
as attachment as well since i've said we neededAttach all parts
. This is true, so to correct that, yourBodyPart
has to be defined as aRawString
, this turns the string into plain text in the BizTalk message part. For completeness i'll put the C# class at the bottom for reference.Now that it's defined as a
RawString
, the SMTP adapter will put this as the body instead of as attachment. As a side effect, the SMTP adapter will no longer put theContent-Description: body
part in the attachment part, but in the actual body part instead. It looks like this:Really nothing else is different except the placement of the
Content-Description: body
part, exactly what we want. Now the email looks fine for every client.The most important properties, besides the ones i already mentioned, must be set as well to make it behave properly:
Content type of your body:
Content type of your attachment:
Attachment filename:
Body character set (will result in
Unknown Error Description
if not set):Make sure you don't set the
SMTP.EmailBodyText
because we already have theBodyPart
for that.RawString class, use it like this in an orchestration
MsgPdfOrder.BodyPart = new Yournamespace.Components.RawString("See attached email.");
: