Skip to Content
Did you ever wanted to post your message as an attachment with the mail adapter?
Did you ever used MessageTransformBean to set a static name to your attachment?
Finally, did you ever wanted to make it a little more dynamic?

If the answer to the above questions is yes then you should consider trying creating
an adapter module that will enable you to set the attachment’s name dynamically.
It’s rather easy as you can do a simple functionality with just a few lines of code.

In this weblog I’ll try to provide a simple solution which will take an XML tag’s name
from the modules Tab configuration and will set our attachment’s name
from the value found inside this XML tag.

Have a look at the code below:

Let’s prepare a test XML file which we’ll try to send as our attachment.


The last thing we have to set is the configuration in the communication channel – Modules – tab for our adapter module.


Now we test our scenario and if we did everything correctly we should see a new e-mail message with the weblog.xml attachment.

As you can see this weblog provides only a simple solution which can be extended in many ways:

– removing the tag that holds the attachment’s name

– converting the attachment to some other formats (not only xml)

– and many other things

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Alok Sarawat
    In my scenario, I just picks file from File Adapter and send this file as attachment through Mail Adapter. There is no message mapping in between because the files are binary. I am facing the problem that Mail adapter do not send file with original name. My requirement is that I need Original file name.Plz help me
  2. Ricardo Andres Maienza
    Hi michal,

    great weblog, but I’ve a little doubt, the module creates a renamed attachment other than the original payload(addAttachment method)?

    Cause I’m using the CC configuration with the “Keep attachment” and “XI Payload” setting, but a mail with 2 attachement has been created (the first one renamed correctly and the other with a “noname” filename)

    there’s something wrong in my conf?
    Could u help me please?

    thanks a lot.


  3. Nasif Kurmoo
    Just wanted to share some info on this topic since on our project we are not allowed to implement adapter modules but had to implment such a requirement.
    With the help of Stefan Grube blog :
    I have been able to do the dynamic filename in the mapping itself using a mail package XI and generating the mail content mime in a UDF:

    public String generateContentWithAttachment(String body,String attachment,String filename,String boundary,Container container){

        String CRLF = “\r\n”;
        String output = new String(“”);
         output = “–” + boundary + CRLF
               + “Content-Type: text/plain; charset=UTF-8” + CRLF
               + “Content-Disposition: inline” + CRLF + CRLF
               + body + CRLF
        + “–” + boundary + CRLF
        + “Content-Type: application/xml; name=” + filename + CRLF
        + “Content-Disposition: attachment; filename=” + filename + CRLF + CRLF
        + attachment  + CRLF;

         return output;

    seems to be working just great. The attachment for the requirement is either plain/text XML.

    anyhow thanks for your blog too!


    1. Nasif

      Can you expand on this?

      I am unsure how the target mapping works for this?



  4. Avinash Kumar
    Hi michal,
    You have provided great blog.
    I am getting two attachment with same content.
    One attachment contains name as provided in message type and another with untitled.xml.

    In this scenario, checkbox for keep attachment should be checked or not?

    If I am not putting the checkbox I am getting only one attachment but its name is same as subject name(Not the one set by our module).

  5. Raimon Jimenez

    We are developing a flow that in the SOAP adapter we includes an attachment. We are using PI 7.0 and doesn’t contains the class Inputattachments. This function module also will work to attach to SOAP adapter instead of MAIL

  6. Akshay Jamgaonkar

    Hi Michal,

    I am having requirement in PI 7.3 to send email attachment with dynamic name.

    Can you please let me know if I can set content-disposition dynamically without mail package,without adapter module in PI 7.3



  7. William Henry

    Hi Michal Krawczyk

    I know that the post is old, but your code save me right now.

    In PI 7.4

    I modify a little your code because the name of the file i recived from the ftp transfer, but the rest of the code is really great.


    William 😎


Leave a Reply