cancel
Showing results for 
Search instead for 
Did you mean: 

Receiver Email Adapter - Attachment Rename!!!

sundararamaprasad
Discoverer
0 Kudos

Hello All,

We are using PI 7.11 SP05. We have a scenario where a file has to be written in a folder as well as sent as an email attachment. The Email attachment should be zipped and the name of that attachment should be filename with extension zi. For an example, if the filename is abc.xml, the atatchment name should be abc.xml.zip . I have the file name (in this case abc.xml) in the dynamic configuration parameter. I wrote a custom adapter module to achieve this result. I'm using this custom adapter module after the payloadzip beanbelow given is the code:

Message msg = (Message)moduleData.getPrincipalData();

Payload payload = msg.getDocument();

MessagePropertyKey msgPropertyKey = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/File");

String fileName = msg.getMessageProperty(msgPropertyKey);

payload.setContentType(contentType + ";attachment;filename=\"" + fileName + "\";");

payload.setDescription(fileName);

payload.setName(fileName);

msg.setDescription(fileName);

msg.setMainPayload(payload);

moduleData.setPrincipalData(msg);

I could see all these values getting assigned ( from the audit log message after each step). But still the attachment is coming as Maindocument.zip . I Kindly request your suggestions on the same.

PS: I have gone through the blogs of Michal, Stefan Grube and sap wiki code for setting attachment name and implemented the code on the suggestions from these blogs.

Thanks,

Sundar

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Have a look at this WiKi, it is describing a slightly different approach but using the additional parameter mentioned could solve your problem as well:

http://wiki.sdn.sap.com/wiki/display/ESOAInfrastructure/Dynamic+Email+Attachment+name+for+Received+M...

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Sundara Rama,

I understand you want to set name for mail attachment.

SAP Note: Mail Adapter sapnote_0000856599

Q: Can I choose the name of an attachment in the mail?

A: Yes. Most mail clients use some heuristics based on some *MIME headers to derive the name of an attachment.* The MIME headers involved in most heuristics are Content-Type, Content-Description,and Content-Disposition. When you create an XI message, the XI payload name is automatically set in the Content-Description. If you want to change or set all of these headers, you can use the MessageTransformBean module (Note 793922) [Link|http://help.sap.com/saphelp_nwpi711/helpdata/en/57/0b2c4142aef623e10000000a155106/frameset.htm]

in the adapter framework.

Q: How can I set the file name of a mail attachment?

There are several MIME headers that play a role in how the client retrieves the file name of an attachment. Unfortunately, this behavior differs among various mail clients. The reason for this inconsistent behavior comes from the fact that this mechanism has been extended incrementally. The old way is to use the name parameter in the Content-Type header as specified in RFC1341. For example, you can set the content type of an XML attachment as:

Content-Type: application/xml; name="abc.xml"

RFC1521 discourages the use of this name parameter in anticipation of the new header Content-Disposition, which is defined in RFC1806.

With this Content-Disposition header, you can set the file name as:

Content-Disposition: attachment; filename="abc.xml"

Some clients may show the Content-Description value as the file name. The Content-Description header is typically used to associate some descriptive information to an attachment (RFC1341) as in

Content-Description: my xml file

To avoid potential interpretation problems, it is recommended to combine the use of these headers.

Regards,

Raghu_Vamsee