Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Sending an email from UDF and including an attachment

Hello all,

I am trying to send an email from a UDF and want to include the original message as an attachment to that mail.

Basically the body of the mail tells me there was an error and the attachment is the response received from the business system.

For this I have written/copied the following code:

First I create the attachment based on the input field errorMsg (which is the header segment "returned as xml" and thus the whole response message)

GlobalContainer globalContainer = container.getGlobalContainer();

OutputAttachments outputAttachments = globalContainer.getOutputAttachments();

Attachment attachments = outputAttachments.create("ByDesign_Response.xml", "text/xml", errorMsg.getBytes());

outputAttachments.setAttachment(attachments);

Then I create the body of the mail:

String mailxml = "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">" +

    "<Subject>Error</Subject>" +

    "<From> etc ...   

And then I call the channel and send out the payload through that channel

Channel channel = LookupService.getChannel(component, comChannel);

SystemAccessor accessor = LookupService.getSystemAccessor(channel);

InputStream inputStream = new ByteArrayInputStream(mailxml.getBytes());

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload mailOutPayload = null;

mailOutPayload = accessor.call(payload);


In the receiver channel I set "Use Mail Package" in the mail attributes, otherwise the body of the mail will be sent out as a an attachment.

The mail with the correct text is sent out but the attachment is not sent, although I see it has been created in the XI Monitor:

Is it possible to send the attachment this way?


Thanks,

Martin

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question