on 07-09-2008 7:25 AM
Hi All,
I have scenario File ---> Mail, monitoring FTP directory for PDF file and sending using mail attachment.
At the moment i am using JAVA mapping to construct the mail package structure follow all the step in this blog :
it is working if i am using text file but then how to encode the pdf content so i can send throught the mail adapter. ?
Thank you and Best Regards
Fernand
Hi,
Actually, i am using this java code below :
try {
// create XML structure of mail package
String output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
+ "<Subject>" + mailSubject + "</Subject>"
+ "<From>" + mailSender + "</From>"
+ "<To>" + mailReceiver + "</To>"
+ "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
+ "<Content>";
out.write(output.getBytes());
// create the declaration of the MIME parts
//First part
output = "--" + boundary + CRLF
+ "Content-Type: text/plain; charset=UTF-8" + CRLF
//+ "Content-Transfer-Encoding: 8bit" + CRLF
+ "Content-Disposition: inline" + CRLF + CRLF
+ mailContent + CRLF
//Second part
+ "--" + boundary + CRLF
+ "Content-Type: Application/pdf; name=" + attachmentName + CRLF
//+ "Content-Transfer-Encoding: base64" + CRLF
+ "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
out.write(output.getBytes());
//Source is taken as attachment
copySource(in, out);
out.write("</Content></ns:Mail>".getBytes());
} catch (IOException e) {
throw new StreamTransformationException(e.getMessage());
}
}
protected static void copySource(InputStream in, OutputStream out)
throws IOException {
byte[] bbuf = new byte[in.available()];
int bblen = in.read(bbuf);
if (!(bblen < 0)) {
//String sbuf = new String(bbuf);
//String encoded = Base64.encode(sbuf);
// replace all control characters with escape sequences
//sbuf = sbuf.replaceAll("&", "&");
//sbuf = sbuf.replaceAll("\"", """);
//sbuf = sbuf.replaceAll("'", "'");
//sbuf = sbuf.replaceAll("<", "<");
//sbuf = sbuf.replaceAll(">", ">");
out.write(bbuf);
}
}
This code working fine with text file but not for pdf file. because i got error in mail adapter :
Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: com.sap.aii.messaging.util.XMLScanException: java.lang.NullPointerException; nested exception caused by: com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 8f(:main:, row:11, col:4)(:main:, row=11, col=4) -> com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 8f(:main:, row:11, col:4)
I guest the problem because the mail adapter doen't accept pdf content insite the mail package.
please advise me
Best Regards
Fernand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
try to use the ISO-8859-1 encoding, making some tests I could open using my browser and xml file that contains a pdf (binary) placed in a xml label.
Anyway, I think the problem you are facing is that as your code is in the adapter, the parser is expecting xml and pdf isn´t.
My scenario is pretty different from yours as it as follows:
SOAP channel
PDF attachment
XML message containing the pdf in base64 must be sent through an HTTP channel.
I solved this developing an EJB that deals with the attachment and create the XML.
Hope this helps, Sergio
Hi Fernand,
You can consider sending the mail via HTTPS protocol or using Digital Signatures. This would encrypt the entire content (Payload+attachments) during transmission.
For content encoding, you can choose one of the options next to Content Encoding under Mail Attributes in the Mail receiver adapter.
Regards,
Riyaz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Madhu,
Thank you for your response, but then i don't want to use abap to send the email. i want to use XI mail adapter. but i have problem to encode the pdf content. int the mail package format.
Best Regards
Fernand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.