cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Filename in Receiver mail adapter - is it possible without custom module or mail package?

Former Member
0 Kudos

Hello All,

We have implemented a file to receiver mail adapter scenario (PI 7.31) , the interface is a pass-through hence no ESR components involved.

Our requirement here is, the source file needs to be sent as mail attachment and attachment name should be dynamic i.e. target file name should be same as that of source file. 

I have searched in SCN blogs and found below solutions :

  1. Using mail package ( We are not keen on implementing this as we don’t use any ESR components)
  2. Michal blog for creating custom module : http://scn.sap.com/community/pi-and-soa-middleware/blog/2006/02/23/xi-dynamic-name-in-the-mail-attac...

      ( Not sure if this will work as I see there are many developers commented in the same link that they are facing issues even after implementing this solution)

So , we are just  looking if there are any other options apart from the above mentioned, in order to achieve the same. If anybody has achieved this through a different method, kindly let me know .

Thanks  in advance.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Kavitha,

We have the same requirement in our project. Could you kindly share what solution was made in your case.

Regards,

Prabhu V

ankit_mishra09
Participant
0 Kudos

Hi Kavita,

I have a similar requirement. Having a xyz.csv file in AL11 & i want that to be mailed as it is with same name to the recipients. If you have found out a solution for this kindly share the same. I don't want to use ESR, is it possible?

Former Member
0 Kudos

Hello Ankit,

We had to go with the ESR development as we cound not find any other better solutions for this.

Thanks,

Kavita

ankit_mishra09
Participant
0 Kudos

Hi Kavita,

I tried doing it, using ICO & no ESR. I was able to receive the file in mail, but couldn't maintain the file name as it was in AL11. We have to use custom java module to make the name dynamic.

iaki_vila
Active Contributor
0 Kudos

Hi Kavita,

I think the main problem is that the attachment treatment changes between PI 7.0 and below to PI 7.1 and above. For example to PI 7.0: Adapter Module PI 7.0 Set Attachment Name - Process Integration - SCN Wiki

If you don't want ESR development, neither custom module development, as far as i know there it not alternative.

Regards.

Former Member
0 Kudos

Hi Kavita

Without using mail package , you will not be able to create the attachment using dynamic name.

You can use message transformation bean to rename the attachment but this will only allows static values.

The simple solution would be use mail package and get the attchment name dynamically. You can do this either by graphical or java mapping.

You have to fill these three fileds in the target mail package

Content Type: text/xml

Content Description:  indratest.txt

Content Disposition:   attachment;filename="indratest.txt"

Sample Java Mapping Code:

package com.test;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class createAttachment extends AbstractTransformation {

  public void transform(TransformationInput arg0, TransformationOutput arg1)

  throws StreamTransformationException {

  try {

  InputStream is = arg0.getInputPayload().getInputStream();

  // get the file name from header

  DynamicConfiguration conf = arg0.getDynamicConfiguration();

  DynamicConfigurationKey dynKey = DynamicConfigurationKey.create(

  "http://sap.com/xi/XI/System/File", "FileName");

  String filename = conf.get(dynKey);

  // creating the attachment

  String ContentType = "text/xml";

  BufferedReader br = new BufferedReader(new InputStreamReader(is));

  String strLine;

  StringBuffer data = new StringBuffer();

  StringBuffer content = new StringBuffer();

  String ls = System.getProperty("line.separator");

  String firstline = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:Mail xmlns:ns1=\"http://sap.com/xi/XI/Mail/30\">";

  data.append(firstline);

  String lastline = "</ns1:Mail>";

  // Read File Line By Line

  while ((strLine = br.readLine()) != null) {

  // Print the content on the console

  content.append(strLine);

  content.append(ls);

  }

  String body = "<Subject>Test Mail using Mail Package in SAP PI</Subject><From>mailpackage@Cognizant.com</From><To>Indrajit.Sarkar2@cognizant.com</To><Content_Type>"

  + ContentType

  + "</Content_Type><Content_Description>"

  + filename

  + "</Content_Description><Content_Disposition>attachment;filename=&quot;"

  + filename

  + "&quot;</Content_Disposition><Content>"

  + content.toString() + "</Content>";

  data.append(body);

  data.append(lastline);

  // Close the input stream

  br.close();

  arg1.getOutputPayload().getOutputStream().write(

  data.toString().getBytes("UTF-8"));

  } catch (Exception e) {

  e.printStackTrace();

  }

  }// end of transform

}