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

孤者浪人 提交于 2021-01-27 12:16:54

问题


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?


回答1:


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;
}



回答2:


You can do this in an orchestration within a message assignment shape. Using a multipart, message would look like this:

Message.part(MIME.FileName) = "your file.name";



来源:https://stackoverflow.com/questions/11971450/why-cant-i-change-the-attachment-name-of-the-body-part-via-the-biztalk-smtp-ada

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!