Hi Experts,
Kindly help me with this error in receiver mail adapter. I tried using Java mapping to send a file as attachment in mail .
Jre version :6
Jse Version :1.6
PI : 7.40
Code where my E-mail Id is specified :
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
String mailSubject = "hi";
String mailSender = "\"<abc@xyz.com>";
String mailReceiver = "\"<abc@xyz.com>";
String attachmentName = "mail.txt";
String replyto="";
String boundary = "--AaZz";
String mailContent = "test mail";
String CRLF = "\r\n";
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>"
+ "<Reply_To>" + replyto + "</Reply_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-Disposition: inline" + CRLF + CRLF
+ mailContent + CRLF + CRLF
//Second part
+ "--" + boundary + CRLF
+ "Content-Type: application/xml; name=" + attachmentName + CRLF
+ "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
out.write(output.getBytes());
//Source is taken as attachment
copySource(in, out);
// last boundary
output = CRLF + CRLF +"--" + boundary + "--" + CRLF;
out.write(output.getBytes());
// finish mail package
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[] buf = new byte[in.available()];
in.read(buf);
String sbuf = new String(buf);
// replace all control characters with escape sequences
sbuf = sbuf.replaceAll("&", "&");
sbuf = sbuf.replaceAll("\"", """);
sbuf = sbuf.replaceAll("'", "'");
sbuf = sbuf.replaceAll("<", "<");
sbuf = sbuf.replaceAll(">", ">");
out.write(sbuf.getBytes("UTF-8"));
}
Please help