Quantcast
Channel: SCN : Unanswered Discussions - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 6719

Sending an email from UDF and including an attachment

$
0
0

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:

attachment.png

 

Is it possible to send the attachment this way?

 


Thanks,

Martin


Viewing all articles
Browse latest Browse all 6719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>