Gotcha When Programatically Sending Email to BizTalk
So here's an obscure one, but odds are it'll help some poor sap a year from now. I was programmatically sending an email message (plus attachment) to
a mailbox polled by a BizTalk POP3 receive adapter. I was able to process it fine, and read all the necessary context information from inside an
orchestration using an expression such as ...
MessageSubject = Message_1(POP3.Subject);
Nothing too fancy there. However, I should also be able to get information about the attachment itself, which wasn't coming through. For instance,
I wanted to get the actual name of the file attached, and should be able to access it by doing this ...
MessageFileName = Message_1.Attach(MIME.FileName);
In the above scenario, Attach is the name of a message part in the multi-part message.
After banging my head on the desk awhile, I asked our internal team for help. It turns out that the MIME decoder looks for the Content-Disposition
value of the attachment, which I wasn't setting in my .NET code. If I tried sending a message from a regular email client, the correct encoded format looks like
this ...
So, moral of story is if you are using the System.Net.Mail namespace to feed messages into BizTalk, make sure you set the Content-Disposition so that
you get access to MIME encoding values on the attachment.