on 06-03-2015 4:01 PM
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
Hi Martin,
If you want i will share the Java Mapping code that will send the email as a notification with payload as an attachment.
Regards,
Srikanth Mavuri.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
Have you tried above requirement by using Java Mapping... By Using Java Mapping we can send mail with attachment ( Payload)....
I think by Java Mapping we can achieve your requirement..
Regards,
Srikanth Mavuri.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try removing <Content_Disposition> tag while forming email package.
Use content type and content only. May be it works. And attach the message as you are doing it in your UDF currently.
"<Content_Type>text/plain</Content_Type>"+CRLF+
"<Content>"+"This content should be present in email body"+"</Content>"+CRLF+
No need to create attachment like that, just try this,
String CRLF="\r\n";
String errorMsg="Error occured due to this reason";
// forming Email Package
String emailPackage=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+
"<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+
"<Subject>Delivery notes</Subject>"+CRLF+
"<From>certificates@ .com</From>"+CRLF+
"<To>ambuj.mishra@ .com;someoneelse@ .com</To>"+CRLF+
"<Reply_To />"+CRLF+
"<Content_Type>text/xml</Content_Type>"+CRLF+
"<Content_Disposition>attachment; filename="+"\""+"ByDesign_Response.xml"+"\""+"</Content_Disposition>"+CRLF+
"<Content>"+errorMsg+"</Content>"+CRLF+
"</ns:Mail>";
This will create your attachment in your email.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ambuj,
Thanks for your reply.
Your code does indeed create an attachment, but this way the body of the email is empty again. All content is placed in the attachment.
I have tried to create emailPackage string with boundaries so that I can use one part as the body and one part as the attachment, but so far I could not get that to work either.
Another thing is that the name of the attachment is always ATT0001.xml in stead of the name specified in the content-disposition.
Kind regards
I have tried to create emailPackage string with boundaries so that I can use one part as the body and one part as the attachment, but so far I could not get that to work either.
Recently I had requirment like you and i tried this boundry thing many time but it didn't work for me also.
I finally resolved this issue by putting something in <Content> and <Content_Type> node of email package.
Apparently my email server was not triggering emails, when these 2 tags were empty.
I had 2 attachment in email, so I attached one using outputAttachments.setAttachment(attachments);
and another attachment i had provided in content like this, so that email gets triggered.
"<Content_Type>text/xml</Content_Type>"+CRLF+ "<Content_Disposition>attachment; filename="+"\""+"attachmentName.txt"+"\""+"</Content_Disposition>"+CRLF+
"<Content>"+"my 2nd attachment content"+"</Content>"+CRLF+
So I would suggest you to create attachment as you are creating now in your code and put your mail body part in content.
Another thing is that the name of the attachment is always ATT0001.xml in stead of the name specified in the content-disposition
May be you are overwirting or hardcoding it somewhere,check again.Attachment name would be as present in disposition tag.
Hi Martin,
I haven't tried it, but you can try with PayloadSwapBean bean. Check the page 5 here http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/6d967fbc-0a01-0010-4fb4-91c6d38c5....
I know this is not your case because in that example move the payload to the attachment, but may be PI thinks the second message is not attachment and you can do a little trick.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Iñaki,
I was thinking the same during the development and have tried it, but somehow the payload swap bean does not see the attachment.
I get the feeling that because I call the channel during the mapping that not all things are available until after the message mapping is completed, since I have also tried to set the filename and directory dynamically (in an attempt to write the files using a file communication channel) and that did not work either.
Kind regards
Hi Martin,
Have you set the Keep Attachments indicator in the Receiver Mail adapter?
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.