XI: Dynamic name in the mail attachment – pseudo “variable substitution”
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


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.
Ricardo
With the help of Stefan Grube blog : https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6321
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!
cheers.
Can you expand on this?
I am unsure how the target mapping works for this?
Regards
Simon
Kindly provide the detailed steps, how you implemented this.
Thanks!
Regards,
Faria
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).
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
Hi Michal,
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
Regards,
Akshay
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.
Regards,
William 😎