locked
How do I do multiple email attachments ? RRS feed

  • Question

  • I tried the following :

    EmailMsg(SMTP.Attachments) = "C:\\BizTalk\\Test.pdf|C:\\BizTalk\Test.pdf\\exampledocument.pdf";

    EmailMsg(SMTP.MessagePartsAttachments) = 1;

    and I get

    A message sent to adapter "SMTP" on send port "SendEmail" with URI "example@email.com" is suspended. 
     Error details: The SMTP send adapter could not find the file C:\BizTalk\Test.pdf\exampledocument.pdf. 

    How do I do multiple attachments ? 

    FYI - I am on BTS 2010 and the email URI is intentionally replaced with invalid address. Both files exist in the directory specified. 




    • Edited by svemaraju Tuesday, January 13, 2015 4:56 PM
    Tuesday, January 13, 2015 4:53 PM

Answers

  • You can't do directly.

    • For each attachment, you have to define separate message part in your email multi-part message. So if you have 3 messages to attach, define email multi-part message with 3 parts.
    • Load the content of the files from drive to a message type variable and assign this message to the multiple part of the message. Something like
    • And change the name to each part using MIME.FileName property.
    EmailMsg.part_attachment1 = msgAttachment1;
    EmailMsg.part_attachment2 = msgAttachment2;
    EmailMsg.part_attachment3 = msgAttachment3;
    
    EmailMsg.part_attachment1(MIME.FileName) = "YourCustomFileName1.pdf";
    EmailMsg.part_attachment1(MIME.FileName) = "YourCustomFileName1.pdf";
    EmailMsg.part_attachment3(MIME.FileName) = "YourCustomFileName1.pdf";
    
    //you can also give names to the attach files
    EmailMsg(SMTP.MessagePartsAttachments) = 2;

    Other option is using custom pipeline and assign the attachment and its name in the code.



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Proposed as answer by DPS Bali Wednesday, January 14, 2015 10:32 AM
    • Marked as answer by Angie Xu Monday, January 19, 2015 2:21 AM
    Tuesday, January 13, 2015 8:04 PM

All replies

  • Check your code, you have typo

    EmailMsg(SMTP.Attachments) = "C:\\BizTalk\\Test.pdf|C:\\BizTalk\Test.pdf\\exampledocument.pdf";

    It shoud be

    EmailMsg(SMTP.Attachments) = "C:\\BizTalk\\Test.pdf|C:\\BizTalk\Test.pdf|C:\\BizTalk\\exampledocument.pdf";

    YOu have "C:\\BizTalk\\Test.pdf|C:\\BizTalk\Test.pdf\\exampledocument.pdf"; There should be "|" symbol between your file paths


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    Tuesday, January 13, 2015 5:52 PM
  • Yes it is a typo.. But i think it should be like this

    EmailMsg(SMTP.Attachments) = "C:\\BizTalk\Test.pdf|C:\\BizTalk\exampledocument.pdf";

    Rachit


    Please mark as answer or vote as helpful if my reply does

    Tuesday, January 13, 2015 5:59 PM
    Moderator
  • Hi,

    In a message assignment expression shape within you orchestration your code should be like below:

    MessageOut(SMTP.Attachments) = 
        "C:\\Attachments\MyFile.pdf|C:\\Attachments\AnotherFile.pdf";

    You simply add a list of files, where the file paths are pipe delimited .it is the easiest way of dynamically adding attachments to an email, and avoids needing to actually load the files into BizTalk.

    Reference  can  be taken from

    Send HTML email in BizTalk with multiple pdf attachments with SMTP adapter

    Thanks

    Abhishek

    Tuesday, January 13, 2015 6:08 PM
  • Can i change the file name of the attachment after doing this ?
    Tuesday, January 13, 2015 7:38 PM
  • You can't do directly.

    • For each attachment, you have to define separate message part in your email multi-part message. So if you have 3 messages to attach, define email multi-part message with 3 parts.
    • Load the content of the files from drive to a message type variable and assign this message to the multiple part of the message. Something like
    • And change the name to each part using MIME.FileName property.
    EmailMsg.part_attachment1 = msgAttachment1;
    EmailMsg.part_attachment2 = msgAttachment2;
    EmailMsg.part_attachment3 = msgAttachment3;
    
    EmailMsg.part_attachment1(MIME.FileName) = "YourCustomFileName1.pdf";
    EmailMsg.part_attachment1(MIME.FileName) = "YourCustomFileName1.pdf";
    EmailMsg.part_attachment3(MIME.FileName) = "YourCustomFileName1.pdf";
    
    //you can also give names to the attach files
    EmailMsg(SMTP.MessagePartsAttachments) = 2;

    Other option is using custom pipeline and assign the attachment and its name in the code.



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Proposed as answer by DPS Bali Wednesday, January 14, 2015 10:32 AM
    • Marked as answer by Angie Xu Monday, January 19, 2015 2:21 AM
    Tuesday, January 13, 2015 8:04 PM
  • Hi,

    Try the settings as below:

    //copy the body part into the multiple-part message

    //set the content type 

    EmailMessage.Body = new RawString("Specify Body content here");
    
    EmailMessage.Body (Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";


    // attach the attachments to the multipart message

    EmailMessage.attachmentOne = msgAttachmentOne;
    
    EmailMessage.attachmentTwo = msgAttachmentTwo;


    //Give names to the attach files

    EmailMessage.attachmentOne(MIME.FileName) = "attach1.xml";

    EmailMessage.attachmentTwo(MIME.FileName) = "attach1.xml";


    //configuration option to specify how BizTalk message parts should be attached to

    //outgoing email message

    EmailMessage(SMTP.MessagePartsAttachments) = 2;


    //set up topic (if using Dynamic Send port)

    EmailMessage(SMTP.Subject) = "subject";
    
    EmailMessage(SMTP.EmailBodyFileCharset) = "UTF-8";
    
    EmailMessage(SMTP.From) = "from";
    
    EmailMessage(SMTP.SMTPHost) = "smtp host";
    
    EmailMessage(SMTP.SMTPAuthenticate) = 2;


    In multi-part message properties you need to configure:

    Body as "Message Body Part" to True

    attachmentOne as "Message Body Part" to False

    attachmentTwo as "Message Body Part" to False

    Alternatively, You can achieve this using Custom pipeline component

    Refer this good post by Abdul Rafay Sending an HTML-formatted e-mail message from BizTalk

    Rachit

    Please mark as answer or vote as helpful if my reply does


    Wednesday, January 14, 2015 4:00 AM
    Moderator