cancel
Showing results for 
Search instead for 
Did you mean: 

Sending file name dynamically including body with out using mail package!!

Former Member
0 Kudos

  Hello Experts,

Need help on the below requirement!!! My scenario is IDoc to Mail. From PI end we need to send the attachment, body and file name to the corresponding recipients. Here is the below development i have made.

ESR part:

   

I have generated body as an attachment by using the below UDF and have mapped it by using Add Variable.

UDF for Body Generation as an attachment:

AbstractTrace trace = container.getTrace();

String content = "Mit freundlichen Gruessen,ThyssenKrupp Steel AG,Materialwirtschaft 1";

String mimeType= "text/plain;charset="+ "\"" + "uft-8" + "\"";

String strFileName = "BODY";

//strFileName = strPrefix  + strFileExtension;

  1. trace.addInfo(strFileName);

try

{

    GlobalContainer globalContainer = container.getGlobalContainer();

    OutputAttachments outputAttachments = globalContainer.getOutputAttachments();

    Attachment attachments = outputAttachments.create(strFileName, mimeType, content.getBytes());

    outputAttachments.setAttachment(attachments);

    return "";

}

catch(Exception e)

{

String exception = e.toString();

return exception;

}

Also I have handled the file Name,TO, Subject and CC with the following UDF and mapped as below

UDF for Dynamic configuration for handling the above:

MappingTrace objTrace = container.getTrace();

DynamicConfiguration objDynConfig;

DynamicConfigurationKey objDCKey;

final String NAMESPACE = "http://sap.com/xi/XI/System/Mail";

final String ATTRIBUTE1 = "THeaderTO";  //Recipients TO List

final String ATTRIBUTE2 = "THeaderSUBJECT"; // Subject of The Email

final String ATTRIBUTE3 = "XHeaderName3"; //ContentDisposition

final String ATTRIBUTE4 = "XHeaderName1";  //ContentType

final String ATTRIBUTE5 = "XHeaderName2"; //ContentDescription

//Date objDate = new Date();

//String strFomatedDate = "";

String strFileName = "";

//SimpleDateFormat objSDF = new SimpleDateFormat(strSuffixDateFormat);

try

{

objDynConfig = (DynamicConfiguration) container.getTransformationParameters().

get(StreamTransformationConstants.DYNAMIC_CONFIGURATION );

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE3);

//strFomatedDate = objSDF.format(objDate);//get the current date and time for file name

strFileName = strPrefix  + strFileExtension; //setting the file name dynamically

strFileName = "attachment; filename=" + strFileName;

  • objTrace.addWarning(strFileName);
  • objDynConfig.put(objDCKey, strFileName);

strFileName = "text/plain;";

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE4);

  • objTrace.addWarning(strFileName);
  • objDynConfig.put(objDCKey,  strFileName);

strFileName = strPrefix ;

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE5);

  • objTrace.addWarning(strFileName);
  • objDynConfig.put(objDCKey, strFileName);
  1. container.setParameter(StreamTransformationConstants.DYNAMIC_CONFIGURATION, objDynConfig);

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE1);

  • objDynConfig.put(objDCKey, ZEmail);

objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE2);

  • objDynConfig.put(objDCKey, Subject);

}

catch (Exception objException)

{

  • objTrace.addWarning(objException.getMessage());

}

return "";

Integration Builder Part:

Here are the below channel settings parameters for my received mail output without using mail package

Parameter Level Setting:


Module Level Setting:


So from the above development I have almost achieved my requirement except File name of the attachment .

Here is the below Output of my mail received:



I kindly request your help on the same so that I can complete my development.

Thanks a lot in advance!!!

Many Thanks,

Best Regards,

Prashanth Bharadwaj Ch.

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Prashanth

In your previous thread , I suggested following the blog by using a Java mapping to form the target payload. But I noticed that you are using UDFs instead.

I've also mentioned that the modules (FCC, Swap, etc) that you configured at the beginning is no longer applicable, but it's still in your channel.

I'm not really sure what approach you are using now.

Can you post the output of your mapping?

Rgds

Eng Swee

Former Member
0 Kudos

Hi Eng,

     My Mapping output is XML payload itself. After it has entered to channel by using strict xml2plain bean and keep attachments the xi payload is getting converted to flatfile and is being sent as an email. Almost i have achieved the requirement Eng except file name. As you could see my mail output in my previous blog.

Below is the screen shot of mapping with xml format and xml format as well.

     

Kindly help on the same so that my development will be completed with out using mail  package!!

Thanks in advance!!

Many Thanks,

Best Regards,

Prashanth Bharadwaj Ch.

engswee
Active Contributor
0 Kudos

If you use the PayloadSwapBean module, the attachment will always be named MainDocument (because it was originally the MainDocument payload).

That is why I suggested to use the Java mapping to fully create the whole MIME structure.

If you insist on using PayloadSwapBean, you need some module after that to modify the Content Type for the attachment to rename it, but unfortunately there is no standard module that can rename it dynamically.

Former Member
0 Kudos

Hi Eng,

     Thanks for your patience!!! I have found the following link for writing module level code to send dynamic file name or will implement java mapping!! .

http://scn.sap.com/community/pi-and-soa-middleware/blog/2006/02/23/xi-dynamic-name-in-the-mail-attac...

So is that fine if i implement the above code in the link at the module level. Please confirm.

Thanks again for the help!!!

Many Thanks,

Best Regards,

Prashanth Bharadwaj Ch.

engswee
Active Contributor
0 Kudos

If you are familiar and comfortable with developing an adapter module, then by all means you can try the above.

But note that the approach requires you to store the filename in field of the target payload, so that the module can retrieve it from there. This would require you to create an extra field in your definition, and make sure that your FCC does not convert that.

Alternatively, you can store the filename into Dynamic Configuration during message mapping, and retrieve it from there in the adapter module. You can choose whichever you prefer.

Former Member
0 Kudos

Thanks alot Eng for the answer!! Will try to implement the same and keep you posted!!

Thanks again!!

Many Thanks,

Best Regards,

Prashanth Bharadwaj Ch.

Answers (0)