Skip to Content
Business Driver
Purchase and Sales information is sent from a partner via Email as a CSV attachment.
PI has to poll the Email server, retrieve these mails and write the CSV files in PI server directory with exactly the same name as the mail attachment.
 
Solution
   
This requirement has popped up many times in the sdn forums
and the solution to this currently is to deploy a custom adapter module
But the same requirement can be sufficed with absolutely no coding or creation of adapter modules.
This can be achieved with 3 standard beans:
MultipartHeaderBean ,PayloadSwapBean and DynamicConfigurationBean
In this blog I have highlighted only the specific settings that have to be maintained
in the communication channels to achieve our requirement, all the other ESR & ID objects should be created as usual.
Sender Email Channel Settings
In the sender email communication channel make sure to check the ‘Keep Attachments’ option , which is required to retain the attachment.
Also check the ‘Set Adapter-Specific Message Attributes’ option to enable the Dynamic Configuration attributes to be available.
Pic 1.1
New Picture.png
Pic 1.2
New Picture (1).png
The MultipartHeaderBean enables us to access the attributes of other payloads that are appended to the XI message as
an additional attachment.
In the ‘Module’ tab add the MultipartHeaderBean with the following parameters:
Parameter Name                Parameter Value       
requiredHeaders All
dcNamespace
 
Using the PayloadSwapBean here we can replace the application payload of the XI message
i.e. email content, with another payload that is appended to the XI message i.e. the attachment
Add the PayloadSwapBean with the following parameters:

Parameter Name                Parameter Value       
swap.keyName    Payload-Name
swap.keyValue   
MailAttachment-1
Pic 1.3

New Picture.png

Receiver File Channel Settings

 

Now in the Receiver File adapter we are going to use the DynamicConfigurationBean to retrieve the attachment name.

The attachment file name is available in the Dynamic configuration attribute Part[1].Content-Description, which we will write to the PI message interface name.

To the ‘Module’ tab add the  DynamicConfigurationBean with the following parameters:

Parameter Name                Parameter Value       
key.0                     

write http://sap.com/xi/XI/System/Mail  Part[1].Content-Description

value.0                   

message.interface

Pic 2.1

New Picture (1).png

Using Variable Substitution, create a variable fname referencing the message interface name and access this variable in the file name field.

Pic 2.2

New Picture.png

Pic 2.3

New Picture (1).png

   

Testing

 

The configurations are complete. It’s time to test our scenario.

A sample mail is sent to the mail account which the sender email adapter is polling with the attachment name MyAttachment1.CSV

Pic 3.1

New Picture.png

Integrated configuration was used in this scenario, so we can see the Dynamic Configuration message attributes in message monitoring.

Note that Part[1].Content-Description has been set to MyAttachment1.CSV at runtime.

Pic 3.2

New Picture (1).png

The payload was swapped successfully and the attachment data has been set to the main payload as shown below.

Pic 3.3

New Picture.png

We can see the output file in the output folder path with the same name as our attachment MyAttachment1.CSV.

New Picture (1).png

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

      1. Rams G

        Hi Sivasakthi,

        Is it possible to pick the .PDF files from Emails and place them on FTP server with the same file name?

        thanks-

        Ramesh

        (0) 
  1. dhinesh kumar raj kumar

    Hi Sivasakthi,

    I am working on a file to mail scenario in which i have to send the files as attachment with the same name of the source file i am sending…but, the received mails are not having the same names for the attachments..My requirement is to set these names to the attachments dynamically..I am a fresher to PI..can you please help me to resolve my issue

    (0) 
  2. Deepak Ravi

    Hi Sivasakthi,

    Your blog helpmed me a lot in creating the same with SOAP attachments.

    Everything worked fine, except the file name generation. In dynamic configuration the file name is coming as <filename.ext>. As ‘<‘ and ‘>’ are not permitted in creation of file name, PI is generating it with underscores (_filename.ext_).

    Dynamic_Conf.JPG

    Filename.JPG

    I rectified this issue by using an UDF. But just want to know is there any other way to get the correct file name in adapter level.

    Regards,

    Deepak Ravi

    (0) 
    1. Elmar Fritz

      Hello!

      I tried to implement this, but it always fails with this error …

      SOAPFault empfangen vom Integration Server. ErrorCode/Category: XIProtocol/WRONG_VALUE; Params: SOAP:Envelope(1)SOAP:Header(1)sap:DynamicConfiguration(3)sap:Record(2), attachment; filename=”=?iso-8859-1?Q?Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?==?iso-8859-1?Q?=5F2014.pdf?=”; size=27653;creation-date=”Tue, 08 Jul 2014 13:32:58 GMT”;modification-date=”Tue, 08 Jul 2014 13:32:58 GMT”, ST: ST_XMS_MSGHDR30_DYNAMIC; AdditionalText: An error occurred when deserializing in the simple transformation program ST_XMS_MSGHDR30_DYNAMIC; ApplicationFaultMessage: null; ErrorStack: XML tag SOAP:Envelope(1)SOAP:Header(1)sap:DynamicConfiguration(3)sap:Record(2) (or one of the attributes) has incorrect value attachment; filename=”=?iso-8859-1?Q?Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?==?iso-8859-1?Q?=5F2014.pdf?=”; size=27653;creation-date=”Tue, 08 Jul 2014 13:32:58 GMT”;modification-date=”Tue, 08 Jul 2014 13:32:58 GMT” An error occurred when deserializing in the simple transformation program ST_XMS_MSGHDR30_DYNAMIC Data loss occurred when converting attachment; filename=”=?iso-8859-1?Q?Preisliste=5FZertifizierungsgeb=C3=BChren=5Fbrutto=5Fnetto?==?iso-8859-1?Q?=5F2014.pdf?=”; size=27653;creation-date=”Tue, 08 Jul 2014 13:32:58 GMT”;modification-date=”Tue, 08 Jul 2014 13:32:58 GMT”


      Unbenannt.JPG

      (0) 

Leave a Reply