Gokul's Blog

Sending multiple attachments with SMTP Adapter

Leave a comment

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):

  • 0 – No BizTalk message parts will be used as attachments.
  • 1- The BizTalk message body part is sent as an e-mail attachment. In this case, the EmailBodyFile or EmailBodyText properties should be specified. If neither of these properties are specified, the BizTalk message body part is sent as the e-mail body instead of as an attachment.
  • 2 – All parts are sent as attachments. However, if EmailBodyText or EmailBodyFile are not specified, then the BizTalk message body part is sent as the e-mail body and other parts are sent as attachments.
  • 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) = "sendmail@testingtvgingestmail.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:sendmail@testmailsource.com"/>

    Technorati Tags: ,

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s