cancel
Showing results for 
Search instead for 
Did you mean: 

Mail (zip mail attachments) to File (unzip)

Former Member
0 Kudos

Dears,

My scenario is Mail to File. PI (7.40) has to pick multiple PDF documents from email and place them on receiver File system with the same name. In this case, I have using blog Attachments zipping during Mapping  created by Praveen Gujjeti

Observations.

At execution

1. I can see that, there are 2 attachments in incoming message

2. After mapping, I can see that the attachments are getting zipped with message id as in name. - like in below screenshot

3. I don't know why it is showing like "application/xml"

At receiver side

1. I have to use File Adapter to place the zip file on file system

Issues/Need Suggestions

1. I don't know how to place this on file system

2. What file name should i provide on receiver file adapter

3. what about remaining 2 attachments - i need only the zipped file

4. How to unzip the file and place the files with the same name on receiver file system

Thanks for your kind help in advance.

regards

Rams

Accepted Solutions (0)

Answers (4)

Answers (4)

apu_das2
Active Contributor
0 Kudos

Hi,

Use below module parameters in your sender Mail CC -

1   AF_Modules/MultipartHeaderBean Local Enterprise Bean   0

2   AF_Modules/PayloadSwapBean Local Enterprise Bean      1

3   sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean  Local Enterprise Bean    mail

0    dcNamespace      http://sap.com/xi/XI/System/Mail

0    requiredHeaders  All

1    swap.keyName    Payload-Name

1    Payload-Name     MailAttachment-1

And use DynamicConfigurationBean in your File receiver CC to keep the exact name -

1   AF_Modules/DynamicConfigurationBean Local Enterprise Bean   1

2   CallSapAdapter Local Enterprise Bean   0

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

1   key.value    message.interface

Use variable substitution to take the dynamic file name from message interface and use that in target file name-

variable substitution -

TargetFile    message:interface_name

In target file name -    %TargetFile%

You can adjust accordingly for multiple attachments.

Thanks,

Apu

Former Member
0 Kudos

Hello Apu,

I tried your suggestion, it works for 1 attachment only.

Same suggestion i tried to use for processing multiple PDF attachments. Hence i used new Module parameters as per Note 2040884.

But when i try the new module parameters with Dynamic Configuration by clicking set adapter-specific message attributes...

the DynamicConfiguration is not working. At receiver file adapter it says no file name exists due to no dynamic configuration parameters.

I don't know how to achieve my solution here.

thanks

Rams

turmoll
Active Contributor
0 Kudos

Rams,

The alternative approach could be getting familiar with this note:

https://launchpad.support.sap.com/#/notes/2040884/E

and treating attachment as separate messages.

You can use java mapping to zip the files. You can set the file name dynamically too. 

Or even you can try to use standard module to ZIP files on receiver side too instead of java mapping, but maybe adapter module on receiver file channel might be needed (or maybe just variable substitution)  in tandem with MultipartHeaderBean  on sender mail adapter side (to keep file names in dynamic configuration).

Good luck!

turmoll
Active Contributor
0 Kudos

Hello,

I rethink it again and rather you will not be able to achieve the goal without "Processing Mail attachments as PI messages" since receiver adapter does not support many attachments.

It would be feasible with ONLY one attachment and and PayloadSwapBean module. Otherwise not.

/k

ps. do not kill the messager.

Former Member
0 Kudos

Thank Jakub for your suggestions...

As per your comment "without "Processing Mail attachments as PI messages"

I have configured the mail adapter as per OSS note '2040884'

PI is able to process message for each attachment in email

I can see 2 messages in PI for each attachment.

Please find the issues faced

1. The attachment is missing - No attachment (please check in above 2 messages)

2. When i click on it, it asks to save on directory but it is getting corrupted.

3. Dynamic Confuguration is missing

Due to dynamic configuration i couldn't able to write the exact file on receiver file adapter. 

Could you please help how to rectify this issue?

Thanks

Rams

turmoll
Active Contributor
0 Kudos

Ad.3. Use adapter module MultipartHeaderBean with parameters:

requiredHeaders = All

dcNamespace = http://sap.com/xi/XI/System/Mail

Ad.1. Attachment is not missing. It is not displayed since content type is not set properly (it is used default). Try to download file, it will be ok.

Ad.2. You can use try to use module MessageTransformBean in sender mail adapter after MultipartHeaderBean to set up the content type with parameter:

Transform.ContentType = application/pdf

Regards,

k

Former Member
0 Kudos

Dear Jakub,

Sorry for the delay in response. I was in Vacation.

I have configured the sender mail adapter as per your suggestion, but the module is getting failure without giving any proper information.

Could you please check whether i am doing wrong at configuration?

Configuration:

Error:

Thanks

Rams

turmoll
Active Contributor
0 Kudos

The namespace must be exactly as I wrote.

/Jakub

Former Member
0 Kudos

Thank you Jakub,

I have changed the namespace as per your suggestion and now the message is picked from mail box.

please find the screenshots below for the result.

From RWB

here i can see 3 message - 1 is for the original mail message, another is for the 1st attachment and last one is for the second attachment.

From SXMB_MONI

3 Messages are been processed well

1st message is payload

following screenshot is from 2nd/3rd messages

Issues:

1. Both PDF Files are coming like Payloads instead of attachments

2. When i Open it is corrupted

3. Tried to save the PDF and opened, even it is corrupted.

4. How to configure receiver File Adapter

Thanks

Rams

turmoll
Active Contributor
0 Kudos

Ad1. Good. Otherwise, you have a problem in file receiver adapter.

Ad2. Try ContentEncoding = base64 in mail adapter

Ad3. Ref. Ad2.

Ad4. If you need to zip them, add the module PayloadZipBean

If you do not need "third" message i.e. email, you can turn it off by parameter. Ref. Note.

Regards,

Jakub

Message was edited by: Jakub Turminski I have just read title again, you have zipped attachments. Obviously use PayloadZipBean module in mail adapter to unzip them. Do not use java mapping etc. /k

Former Member
0 Kudos

Dear Jakub,

I have used 'Base64' as ContentEncoding, but the issue is same.

And also i have set 'adapter-specific message attributes' check box but in Moni there is no values from DynamicConfiguration.

How to solve this issue?

thanks

Rams

turmoll
Active Contributor
0 Kudos

I'm slightly confused with your scenario.

Are your PDFs zipped or not (ref title: Mail (zip mail attachments) to File (unzip))?

If they are zipped you need to uzip them first. When you download payload you actually download zippped pdf. (However, you set content type as pdf which is wrong.)

Maybe ASMA are not filled in for "attachment" messages. Can you check "Dynamic Configuration" of Main Payload message?

Former Member
0 Kudos

Dear Jakub,

My actual requirement is - pick multiple pdf attachments from a mail and place them on File Adapter with the same name and extension (.pdf) of attachment.

I was try to accomplish this via zip all attachments and place the zipped file on File Adapter.

--> In your second and third message, you have suggested like following..

The alternative approach could be getting familiar with this note:

https://launchpad.support.sap.com/#/notes/2040884/E

and treating attachment as separate messages.

And also

I rethink it again and rather you will not be able to achieve the goal without "Processing Mail attachments as PI messages" since receiver adapter does not support many attachments.


--> Hence i have started to implement Note 2040884.


regarding you latest message '(However, you set content type as pdf which is wrong.)'  you only suggested me to use application/pdf in one your reply


Transform.ContentType = application/pdf



So in this case, could you please suggest me which is best option to achieve my requirement - pick multiple attachments from a email and place them on File system with the same name and extension


Thanks a lot for your support


Regards

Rams

turmoll
Active Contributor
0 Kudos

I have configured similar scenario as your in my system i.e. SAP PO 7.4 SP12 and I must admit that PDFs got corrupted after they were processed by sender mail adapter with parameters

  • Attachment.ContentType= application/pdf
  • Mail.CreateMessageForAttachments = true

configured as in Note 2040884 - Processing Mail attachments as PI messages . It seems either this note is relevant only for "text" attachments (there are explicite examples with text/xml and application/xml in the note) or there is bug which you can boldly report via OSS to SAP.

If I were you, I would enquire via OSS message if it is only applicable for "text" attachments or can be used for binary too.

If it's only for text attachments, than you need to look for an alternative solution.

Regards,

k

Former Member
0 Kudos

Yes Jakub,

I have raised OSS Message on this, waiting for the SAP reply

thanks

Rams

manoj_khavatkopp
Active Contributor
0 Kudos

Ram,

In the java code:


Attachment newopAttachment = out.getOutputAttachments().create(msgID + ".zip", baos.toByteArray())

msgID refers to the PI message ID so you are getting msgID.zip as filename

change the code accordingly to get your desired filename.


//remove each attachment if required. Uncommonent below 

//trace.addInfo("Removing Attachment no: " + (i+1) + " & Name: " + attachmentID);                              //outputAttachments.removeAttachment(attachmentID);

you need to remove the comment so that you can remove the unwanted files.

according to the code the zip file will be passed as an attachment to the output payload so use Payloadswap bean to place the zip file.

Br,

Manoj

Former Member
0 Kudos

Hello Manoj,

I have done as per your suggestion - to un-comment the code to remove attachments and tested. As a result now the zip file itself is getting removed. 😞

Thanks
Ramesh

Former Member
0 Kudos

Please ignore my previous reply,

I was verifying at wrong place.

The attachments were not removed, but the zipped file was exists

thanks-

Rams

former_member186851
Active Contributor
0 Kudos

Hello Ram,

The mail attachements you wish to ZIP and place in the file directory?

if yes,Check the payloadZip bean

Adding PayloadZipBean in the Module Processor - SAP NetWeaver Process Integration - SAP Library