cancel
Showing results for 
Search instead for 
Did you mean: 

how to set Content-Type in Mail

Former Member
0 Kudos

Hi All,

I have a requirement in which I need to read the email attachment and perform the mapping.

I am able to read the content through JAVA UDF but I am facing problem with the File encoding.

It is showing the Email Attachment Content as "application/octet-stream;name="abc.xml" and I am wondering if anybody know how to convert this Content-type into "text/xml".

I have tried this but it's not working

Content = attachmentContent.setContentType("text/xml");

Is there any way we can set the file encoding to UTF-8 in JAVA UDF or can anybody tell me the how to read the email attachment through UDF or XSLT?

Thanks,

Iqbal

Accepted Solutions (0)

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Mail attachment supports MIME type.

Can you try setContentType("application/xml"); 

or

setContentType("application/xml; charset=utf-8");  and see how that helps.

Former Member
baskar_gopalakrishnan2
Active Contributor
0 Kudos

You basically need to use the response object to call this method setContentType(). THats why you get the above error. Is your attachmentContent is response? Try with this or provide your code details ...

Former Member
0 Kudos

Hi Baskar,

I am not using any response object I am just getting the email content and return that as it is but by default it is not using the UTF-8 encoding so I need to set the encoding.

I am using this function

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();


attachmentContent = new String(attachments.getContent());

attachmentContent.setContentType("application/xml; charset=utf-8");
baskar_gopalakrishnan2
Active Contributor
0 Kudos

attachtmentContent is the string object. You cannot do this way... You have to see the below sap help links for how to get outputAttachments from globalContainer object and create Attachment object for contentType and finally set the attachment using outputAttachment..  Refer this link

http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mappingtool/tf7/rt/GlobalContainer.html

http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html

Former Member
0 Kudos

HI Baskar,

Is it possible for you to provide me the code or correct my code?

I am trying this but still getting an error.

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

OutputAttachment outputAttachments = globalContainer.getOutputAttachments();

attachmentContent = new String(attachments.getContent());Attachment attachments = inputAttachments.getAttachment(attachmentID);

OutputAttachment = Outputattachment.setContentType("application/xml; charset=utf-8");

result.addValue(attachmentContent);

baskar_gopalakrishnan2
Active Contributor
0 Kudos

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

Attachment inputAttachments = inputAttachments.getAttachment(attachmentID);

OutputAttachment outputAttachments = globalContainer.getOutputAttachments();

Attachment attach = OutputAttachment.create(attachmentID, "application/xml;charset=utf-8",  attachments.getContent());

result.addValue(attach.getContent().toString());

Note: The above coding is sample for you to enhance further. I'm currently not at my desk to compile the code.

Former Member
baskar_gopalakrishnan2
Active Contributor
0 Kudos

change below line as follows use outputAttachments.create  lower case 

Attachment attach = outputAttachment.create(attachmentID, "application/xml;charset=utf-8",  attachments.getContent());