on 12-14-2014 8:35 PM
Hi All,
i have a reqmt to send a html content and .txt attachment after reading a file from a ftp location
I was looking at the below link to achieve this using JAVA mapping but not sure how to send html content. let me know if anyone faced the same
Also, if you could detail out the coding here, that helps.
thx
mike
Sample code. HTML can be generated using XSLT OR Java mapping. Going with Java mapping, to make input payload as attachment.
package javaapplication1;
import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class JavaApplication1 extends AbstractTransformation {
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
// a) Just copy Input file content to Output attachment content
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
transformationOutput.getOutputAttachments().create("FileAttachment", b);
// b) Populate XML for XIPAYLOAD
// Can hard code html or use Parameterized Java Mappings or get values from byte[] b (above).
String htmlContent = "<!DOCTYPE html>\n"
+ "<html>\n"
+ "<body>\n"
+ "\n"
+ "<table style=\"width:100%\">\n"
+ " <tr>\n"
+ " <td>Jill</td>\n"
+ " <td>Smith</td>\n"
+ " <td>50</td>\n"
+ " </tr>\n"
+ "</table>\n"
+ "\n"
+ "</body>\n"
+ "</html>";
String mailOutput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">\n"
+ " <Subject>Subject</Subject>\n"
+ " <From>namea@company.com</From>\n" // Can hard code or use Parameterized Java Mappings
+ " <To>nameb@company.com</To>\n" // Can hard code or use Parameterized Java Mappings
+ " <Reply_To/>\n"
+ " <Content_Type>text/html</Content_Type>\n"
+ " <Content><![CDATA[" + htmlContent + "]]></Content>\n"
+ "</ns:Mail>";
outputstream.write(mailOutput.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Requirement is taking the source file from ftp location and attaching to the email and also extract some of the fields from the file and put it as html content (probably with XSLT)
thx
mike
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.