Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
Today I was working on a BizTalk solution to intercept, transform, and relay emails sent from a LOB system. BizTalk polled a POP3 mailbox and my orchestration replaced the original plain/text email body with some fancy, template driven HTML content and sent it out a dynamic SMTP send port. Only the email body was to be modified, the rest of the email message was to replicate the original email message, including any attachments (that may or may not be present).
To aid in testing I wrote a simple .Net email client. (I got tired of composing a new email in Outlook every time I wanted to test the solution)
The solution worked well (and perhaps I may post about the details sometime later) accept for the fact the outbound message had lost the attachment filenames.
Note: The attachment on the outbound message has a filename of ATT00241.DAT
A helper class in my orchestration inspected the inbound message for attachments and added them to the new outbound message. Each message part (attachment) was assigned the MIME message part context properties of the same inbound message part. What I found was the MIME.FileName property was not being populated by the MIME decoder.
The MIME decoder in the POP3 adapter (when configured to apply MIME decoding) populates the following message part context properties when a MIME encoded message is received:
I checked the message source of the email I was sending (via my DIY email client) to check the MIME headers were present.
Appears OK right?...
content-type: application/octet-stream; name=SampleAttachment.zipcontent-transfer-encoding: base64
Wrong
It turns out the MIME decoder is looking for the content-disposition header values
content-type: application/octet-stream; name=SampleAttachment.zipcontent-transfer-encoding: base64content-disposition: attachment; filename=SampleAttachment.zip
So some quick changes to the Breeze Simple Email Client ...
attach.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachmentattach.ContentDisposition.FileName = Path.GetFileName(attachmentFileName)
...and we were back to cooking with gas.
and now attachments on our outbound message retain their original filename...noysh!
And BTW, not all commercial email clients populate these MIME headers correctly either (or so a friend of a friend who's aunt once knew someone that was talking to a girlfriend at the supermarket said). Check out the message source of items in your inbox. You might be surprised.
Happy spamming er...umm...BizTalking
Remember Me