on 01-08-2014 11:24 AM
In order to dynamically name the attachment in the mail receiver adapter, I deployed the module SetAttachmentName (as shown in wiki Adapter Module PI 7.0 Set Attachment Name - Process Integration - SCN Wiki) into my PI and used it in the my mail receiver comm channel before the mail module. But now when I test it, the whole attachment is coming inside the body of the email and not as an attachment. I have checked in scn blogs but did not find any relevant material for my issue. Did anybody face such an issue while using this custom module?
Hi Syed
You can try Java map also for setting the attachment name dynamically. Make sure that you need to check the option 'Keep Attachment' in the mail adapter
Java map Code:
import com.sap.aii.mapping.api.*;
import java.io.*;
public class JavaMapWithoutMailPackage extends AbstractTransformation
{
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException
{
try
{
DynamicConfiguration conf = arg0.getDynamicConfiguration();
DynamicConfigurationKey dynKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String filename = conf.get(dynKey);
String ContentType = "text";
String CharSet = "UTF-8";
String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();
arg1.getOutputHeader().setContentType(CompositeContentType);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(arg0.getInputPayload().getInputStream()));
StringBuffer sb = new StringBuffer();
String separator = System.getProperty("line.separator");
String line;
while((line = bufferedReader.readLine()) != null)
{
sb.append(line);
sb.append(separator);
}
String srcdoc = sb.toString();
arg1.getOutputPayload().getOutputStream().write(srcdoc.getBytes("UTF-8"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Indrajit,
In PI7.0 there are no similar methods as getOutputHeader, getInputPayload .. etc.
Please see this wiki XI libraries for development - Process Integration - SCN Wiki.
regards,
Syed
Hi Syed
Then try this approach.
Use the mail package and in the message mapping write an UDF and map it to the field 'Content_Type'.
Inside the UDF read the file name and populate the content type in the below format
String ContentType = "text";
String CharSet = "UTF-8";
String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();
return CompositeContentType;
This will work for sure.
Hi Syed
Please use mail package and use a simple java map to populate the output.Below are the sample codes for the same
import com.sap.aii.mapping.api.*;
import java.io.*;
public class JavaMapforAttachmentName extends AbstractTransformation
{
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException
{
try
{
DynamicConfiguration conf = arg0.getDynamicConfiguration();
DynamicConfigurationKey dynKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String filename = conf.get(dynKey);
String ContentType = "text";
String CharSet = "UTF-8";
String CompositeContentType = (new StringBuilder()).append(ContentType).append(";charset=\"").append(CharSet).append("\";filename=\"").append(filename).append("\"").toString();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(arg0.getInputPayload().getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while((line = bufferedReader.readLine()) != null)
{
sb.append((new StringBuilder()).append(line).append("\n").toString());
}
String srcdoc = sb.toString();
String trgdoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
trgdoc = (new StringBuilder()).append(trgdoc).append("<ns1:Mail xmlns:ns1=\"http://sap.com/xi/XI/Mail/30\">").toString();
trgdoc = (new StringBuilder()).append(trgdoc).append("<Subject>Test of Mail adapter</Subject>").toString();
trgdoc = (new StringBuilder()).append(trgdoc).append("<From>test@gmail.com</From><To>test@test.com</To>").toString();
trgdoc = (new StringBuilder()).append(trgdoc).append("<Content_Type>").append(CompositeContentType).append("</Content_Type><Content>").append(srcdoc).append("</Content></ns1:Mail>").toString();
arg1.getOutputPayload().getOutputStream().write(trgdoc.getBytes("UTF-8"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Hello Syed,
I had tried this long back but the scenario failed since my payload was PDF that failed in Adapter, But yours is XML.
I didnt use the Mail Package. But you can try below steps.
Can you try to name Subject Field as same as Dynamic Name(using Java Mapping), You might have to uncheck the Keep attachments tab and also you Need to use PayloadSwapBean to swap payload as attachment.
Regards,
Hiren Asher
Hello,
I believe u have ticked "Keep Attachments" option in ur receiver mail adapter?BTW, u are using mail package?
In addition to that, i think there are other simple ways of setting dynamic attachment name instead of writing AM and one of them is:
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Syed,
I don't have PI7.0, so not sure abt the steps in PI7.0. But i was looking below wiki and here the author is using mail package to accomplish very similar kind of requirement.
Dynamic Email Attachment name for Received Mails - Process Integration - SCN Wiki
Now coming to passing input XML inside content, may be u can think of using XSLT mapping and pass entire input XML data as XML string inside content field and then check the output?
Thanks
Amit Sriavstava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
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.