Search code examples
smtpbiztalkbiztalk-2010

Why can't I change the attachment name of the body part via the BizTalk SMTP Adapter?


I'm attempting to send a message through a BizTalk SMTP Send Port. Specifically, I am sending a message through a "specify-later" port of an orchestration. My goal is to attach the message body to the sent email with an attachment filename of my choosing.

However, no matter what I try the attachment name remains "body.csv"

I have tried:

  1. Multipart message with a single part + set MIME.FileName on this part.
  2. Multipart message with two parts (both attached) + set MIME.FileName on both parts (the non-body part correctly had the attachment name, the body part did not).
  3. Standard message + set MIME.FileName on the message.

I have tried this with all configurations on the SMTP adapter of "Attach only body part" and "Attach all parts" and none worked.

Currently I have "Attach only body part" and some fixed text (configured on the send port) for the email content.

I have read that some have used the MIME Encoder pipeline in past versions of BizTalk, but apparently this is unnecessary with the SMTP Adapter. Others use custom pipeline components to set MIME.FileName which is where I'm heading, but seems unnecessary if the MIME.FileName is already set in my orchestration.

Am I missing something fundamental here for this relatively simple problem?


Solution

  • The second suppose to work. Try using this code (that works for me) from an helper:

    public static void SetFileName(string emailMessage,XLANGMessage message)
    {
        Byte[] b = GetBytes(emailMessage);
        MemoryStream stream = new MemoryStream(b);
        IStreamFactory factory = new BinaryStreamFactory(stream);
        string partName = FileName + "." + FileType;
        message.AddPart(factory, partName);
        XLANGPart part = message[partName];
        part.SetPartProperty(typeof(MIME.FileName), partName);
    }
    
    static byte[] GetBytes(string str)
    {
        byte[] bytes = new byte[str.Length * sizeof(char)];
        System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
        return bytes;
    }