cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic attachment filename in receiver mail channel

0 Kudos

Hello experts,

our landscape is like:

SAP ERP 6.0 EHP 7

SAP PI/PO 7.40

we have the following scenario:

ORDERS05 IDoc via IDoc adapter through the pi with mapping ORDERS05_TO_ORDERS96A to the receiver mail channel adapter which sends an mail with attachment to our vendor.

Our vendor needs an unique filename because he puts all fiels of all customers in one folder. My idea was to set the filename dynamically with the help of ASMA. But whatever I configure, nothing works. I need a filename like 1339_ORDERS_<Ordernumber>_<timestamp>.edi

What kind of information do you need to help me? Any Screenshots?

kind regards

Steffen Albach

Accepted Solutions (1)

Accepted Solutions (1)

Snavi
Active Participant
0 Kudos

Hi Steffen,

you can specify the attachment filename in Content_Disposition field if you are using 'Mail Package' option in receiver channel.

create multimapping

map ORDERS05_TO_ORDERS96A

map ORDERS96A_To_Mail

set Content_Disposition as attachment;filename=xxxx where xxxx is your filename derived in the mapping.

set the content_type

map the content from ORDERS96A to content

use mail package option in your receiver channel

0 Kudos

Hi Navdeep,

thank you for reply.

I did like you said and get the following error message if I check the operation mapping:

What should the target operation be ?

Before I added the ORDERS96A_TO_MAIL Message Mapping the target operation was the Service Interface OrdersD96A_IN

kind regards

Steffen

Snavi
Active Participant
0 Kudos

Hi Steffen,

your target operation should be service IN interface with external message type 'mail'

0 Kudos

Hi Navdeep,

thank you, this problem is solved now but the next is coming up and I've got these error messages:

could you please help me with this?

kind regards

Steffen

0 Kudos

Hi Navdeep again,

the mail now receives my mail account and the attachment name is unique. So the name is like I want it.

The problem now is, that the file is a XML-file but we need an edi file, like flat file.

The localejbs/EdifactConverterModule does not work, I think because of the mail package. Is there any other way to convert this XML file to an edi file?

kind regards

Steffen

Snavi
Active Participant
0 Kudos

Hi Steffen,

yes, the EdifactConverterModule will not work with the mail package as the payload is converted to 'mail' message.

I will advise you to use the EdifactConverter module which is already working for you.

for the attachment file name you can use the modules developed by Eng Swee as mentioned by Vadim in the post

Snavi
Active Participant
0 Kudos

Hi Steffen,

there is another option, we can set the variable header "Content-Disposition" and the variable header value can be mapped to dynamic configuration in your mapping.

use the below udf in your message mapping ORDERS05_TO_ORDERS96A, and remove the mail package mapping from your operation mapping

var1 is your filename which can pass from your mapping

In your message mapping, add a temporary variable to the message structure (say mailHeader)

map this variable with your udf, source of udf will be the dynamic filename that you want (in my case it is ID field in the payload)

In your mail receiver configuration , uncheck the mail package option and in advanced tab set the Variable Header (XHeaderName1) to Content-Disposition

you can keep your module to convert the xml to flat file and it should work

I have used the below blog, please refer this for more information

https://wiki.scn.sap.com/wiki/pages/viewpage.action?spaceKey=ESOAInfrastructure&original_fqdn=wiki.s...

engswee
Active Contributor
0 Kudos

Hi Navdeep

Thanks for sharing this approach. I wasn't aware of this technique and it does work on setting the attachment filename dynamically for an Outlook 365 mail client.

Steffen

You might want to try out Navdeep's approach above. This approach can be achieved using standard functionality and so you do not need to deploy the custom module. One thing to note though is that different mail clients behave differently and as such SAP Note 856599 recommends to populate the filename in 3 MIME headers for consistency sake. The approach above only sets the Content-Disposition header. You can try this first and see if your vendor's mail client can interpret it correctly.

If it does not, then you can additionally try to set the Content-Type header using the method OutputHeader.setContentType(). If after both these cannot work, then you might need to go for the custom module approach which is able to set all 3 headers.

Regards

Eng Swee

0 Kudos

Hi Navdeep,

thank you very much for your reply.

I did like you said and get the following error if I test the mapping by clicking on "Display Queue"

the UDF is the following:

The error-log entry:

can you tell me why the test go to an error?

kind regards

Steffen

Snavi
Active Participant
0 Kudos

Hi Steffen,

Dynamic configuration will work during runtime. Please run the end to end scenario.

Regards,

Navdeep

0 Kudos

Hi Navdeep,

thank you very much for your support. It works fine.

One problem is still ahead. Our Mail System IBM Notes shows an attachment, the mail system Pegasus of our vendor shows the content from the attachment in mail body. The CIO of our vendor now says that the mail is checked by a php script which splits the mail in header, body and attachments and then forwarding this as one to the mail system.

Do you have a solution for this problem?  an automatic forwarding from a mail account of us to him doesnt't work. the manual forwarding works fine.

kind regards

Steffen

engswee
Active Contributor
0 Kudos

Hi Steffen

I'd suggest you check with the CIO (or his team) how the PHP script works? In particular, does it check on some of the MIME headers to determine the splitting.

Additionally, you might want to try to use a normal Mail client to send the email with attachment, and see how the vendor's system work. If it behaves differently from the mail from PI, then ask the client to extract the full mail content (including the MIME parts) for both mails so that you can compare them.

Regards

Eng Swee

0 Kudos

Hi Eng Swee,

thanks for reply.

He answered now, that the content type is "text/plain" and asks if I can send him "multipart/mixed".

I tried the parameter Transform.ContentType as value "multipart/mixed" from Module MessageTransformBean but the vendor didn't receive as.

How should I configure mapping, UDF or receiver channel that content-type is multipart/mixed ?

kind regards

Steffen

engswee
Active Contributor
0 Kudos

Hi Steffen

It might not be as simple as just setting the content type using either UDF or MTB.

What's the requirement - does the email need to have a body, or just an attachment will do? If just an attachment will do, then it shouldn't need "multipart/mixed".

IMHO, you should request for samples from the vendor of:

a) MIME stream of an acceptable email

b) MIME stream of what they are now receiving from your PI system

It might not be a straightforward solution as it seems you now need to tailor-make a solution to suit your vendor's custom PHP logic instead of common industry-standard mail clients.

Regards

Eng Swee

Answers (1)

Answers (1)

vadimklimov
Active Contributor
0 Kudos

Hello Steffen,

Recently developed and published a custom adapter module that can be used to construct dynamic file names for mail attachments - please have a look at his blog (please also note that the referred module is a part of an aggregated custom adapter module development project done by Eng Swee and described in ) This approach requires population of a message dynamic configuration attribute with a desired file name (for example, from a mapping) so that it can be further used by the module. The referenced blog contains illustration on how this can be implemented end-to-end.

Regards,

Vadim

0 Kudos

Hello Vadim,

I found and read this blog already but it doesn't contain information about IDoc to Mail scenario. Nevertheless I configured it nearly completely just without that java mapping which is important, because I don't know how to create it. The Screenshot looks like a function in a message mapping, but where should I set it up?



Can you please explain me how to do that?

kind regards

Steffen

engswee
Active Contributor
0 Kudos

Hi Steffen

I read your comment on my blog but I will reply here instead as the comments section of a blog is not the appropriate place to work through the details of a specific issue.

Firstly, it doesn't matter what is the exact sender adapter type, as generally non file-based sender adapters sets the MIME header with a default file name - MainDocument.xml. For your case, the sender adapter is IDoc, so it matches the particular case and therefore the approach is applicable.

Secondly, for Scenario 1, I just illustrated it with a simple passthrough scenario. The key for this approach to work is that the filename is stored in Dynamic Configuration, and this is typically done at mapping step. Because the sample was a passthrough scenario, I just constructed a simple Java mapping using the approach. I noticed you already have an IDoc to EDIFACT message mapping in place. As such, you do not need to use a Java mapping to set the Dynamic Configuration value. You can just use a UDF in your existing mapping to construct the required file name and set the Dynamic Configuration value. This is a very common technique and you can find a lot of examples on SCN if you are not familiar on this (hint: even Navdeep's reply below has an example).

Also note that, with this approach, it's still okay for you to add the EDIFACT converter module in the processing chain of the receiver mail channel.

If you are still facing any issues, please provide some screenshot of any errors and the work you have done.

Regards

Eng Swee