I’ve received a number of questions regarding a sample I posted a while ago: Arbitrary Binary Attachments to Multi-Part Messages; mostly related to issues when sending the resulting messages through the SMTP adapter and not all attachments (or no attachments at all) getting to the destination account.
I’ve found that usually, this is the result of setting the SMTP.MessagePartsAttachments property to the wrong value. In the sample I posted alongside the article, I was setting the property to 2. I didn’t give any explanation about it at the time, but contrary to what it may intuitively appear, you don’t set this property to the number of attachments (parts) you want to send alongside the message.If you attach 4 different parts to the message, you don’t set the property to the value 4.
Instead, the value 2 means "Send all parts as attachments", which is exactly the behavior you want. For completeness sake, here’s what each possible value for this property means (taken from the BizTalk documentation):
The above article is taken from Tomas Restrepo’s blog. Link to Original Article
Configuring Dynamic Send Port
This has to be set in the MessageAssignment shape of myMsg:
myMsg(SMTP.SMTPHost) = "localhost";
myMsg(SMTP.From) = "email@example.com";
myMsg(SMTP.Subject) = "From Binary Attachments";
myMsg(SMTP.MessagePartsAttachments) = 2;
In a Expression shape, set this value for the Dynamic Send Port:
MyDynamicSendPort(Microsoft.XLANGs.BaseTypes.Address) = System.Configuration.ConfigurationManager.AppSettings["FileorSMTPEmail"];
The above value is taken from the configuration file. I have done this way so that we can write to File System or send to email.
1. <!–<add key="FileorSMTPEmail" value="file://E:\testFileLocation\BinaryAttachments\test.xml"/>–>
2 .<add key="FileorSMTPEmail" value="mailto:firstname.lastname@example.org"/>