cancel
Showing results for 
Search instead for 
Did you mean: 

Sending XI-Content as Mail Attachement with specific Filename

Former Member
0 Kudos

Hi,

I want to send the Message-Content as a mail attachment with a specific Filename (e.g. 2005-08-31.csv). The content is a CSV File, not a XML

In the scenario an IDOC is sent to the XI mapped in a CSV-File (via Java-Mapping) and should be send as a Mail Attachment.

Is this possible and how?

Thank you for your help

Thomas

Accepted Solutions (0)

Answers (1)

Answers (1)

stefan_grube
Active Contributor
0 Kudos

Hi Thomas,

You can influence the filename with the ModuleTransformBean. You need at least SP9 for this feature.

In the Mail Receiver Channel got to tab "Module"

As first module (before the mail module) enter:

localejbs/AF_Modules/MessageTransformBean as Local Enterprise Bean with any key

For this module key you can use in the module configuration following entries:

Transform.ContentDisposition inline|attachment;filename=<filename>
Transform.ContentDescription <Filename>
Transform.ContentType <MimeType>/<SubType>;name="<filename>"

If you want to send an attachment, use:

Transform.ContentDisposition attachment;filename="MyFile.csv"
Transform.ContentDescription MyFile
Transform.ContentType text/plain;name="MyFile.csv"

If you use the Mail Package, you can set the file name that way:

<ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">
  <Subject>Hello</Subject>
  <From>sender@sender.com</From>
  <To>receiver@receiver.com</To>
  <Content_Type>text/plain;name="MyFile.csv"</Content_Type>
  <Content>Here comes the CSV Data</Content>
</ns:Mail>

Hope that helps,

Stefan

Former Member
0 Kudos

Hi Stefan,

I tried the Mail Package method and have one problem. The mail is send correctly, with the csv as an attachment, but the file name is...

payload-7bfa60a11ab511da87b100096b1a234f@sap.com.txt

instead of MyFile.csv.

The Payload contains the following XML...

<?xml version="1.0" encoding="UTF-8"?>
<p2:Mail xmlns:p2="http://sap.com/xi/XI/Mail/30">
<Subject>My Invoice</Subject>
<From>xi@mail.com</From>
<To>me@mycompany.com</To>
<Content_Type>text/plain;name="MyFile.csv"</Content_Type>
<Content>123;A49;aaa</Content>
</p2:Mail>

Thank you for your help

Thomas

stefan_grube
Active Contributor
0 Kudos

Hi Thomas,

even when you use the Mail Package, you have to assign the values for ContentDescription and ContentDisposition with help of the MessageTranformBean as described above.

Regards

Stefan

Former Member
0 Kudos

Hi Stefan,

is it correct that I have to specify a fixed file name?

The file name should be variable (Timestamp + id). Is this also possible with this bean?

Thank you

Thomas

stefan_grube
Active Contributor
0 Kudos

No, is not possible to have dynamic names for the attachments, when you use the MessageTransformBean.

You can only have a dynamic attachment name for the Main Payload by using the Mail Package.

Stefan

Message was edited by: Stefan Grube

stefan_grube
Active Contributor
0 Kudos

In my latest tests in SP13 I used following element in the Mail Package:

<Content_Type>text/plain;charset="ISO-8859-1";name="xyz.txt"</Content_Type>

This worked only, when ContentDescription in the module configuration was not set (but ContentDisposition has to be used).

In this case you can use dynamic attachment names, when when assign the name in the mapping.

There might be some issues in lower releases, so the best would be, if you patch to SP13.

Regards

Stefan

Message was edited by: Stefan Grube

Former Member
0 Kudos

Hi,

I wrote my one bean to add the payload as an attachment to the Email with a dynamic name. But I am not able to change the ContentType to "text/comma-separated-values". As a result my attachment has the correct name (a timestamp) but the ending is always .txt or .bin. In the Interface definition of the Interface Message (com.sap.aii.af.ra.ms.api) is described, that the attachment type can be XML, text or binary. I think that's the problem.

@Stefan

I will try your solution via the Mail Package.

Maybe I can influence the Content Type there...

Thank you for your help

Thomas

PS: we now have SP14

stefan_grube
Active Contributor
0 Kudos

The ContentType text/csv is too new to be considered in the mail adapter.

http://www.rfc-editor.org/rfc/rfc4180.txt

According to the specification, all unknown sub types of text are treated as text/plain.

http://www.ietf.org/rfc/rfc2046.txt

Therefore you are not able do define a suffix .csv at the moment. The only way is, adding the name of the attachment to the ContentType:

text/csv;charset="utf-8";name="myFile.csv"

Regards

Stefan

Former Member
0 Kudos

Oh, the csv content type seems to be from this month, so it is realy new.

I will try today the MailPackage solution.

Thank you

Thomas

Former Member
0 Kudos

Hmm it doesn't work. My payload was the following...

<?xml version="1.0" encoding="UTF-8"?>

<p2:Mail xmlns:p2="http://sap.com/xi/XI/Mail/30"><Subject>Invoices from Endress&Hauser GmbH & Co KG</Subject><From>xxx@xxx.com</From><To>yyy@yyy.com</To><Content_Type>text/csv;charset="utf-8";name="myFile.csv" </Content_Type><Content>A1,A2,A3,A4,A5,A6,A7,A8,A9,

B1,B2,B3,B4,B5,B6,B7,B8,B9,

</Content></p2:Mail>

As the Message-Protocol I choose XIPAYLOAD. At Mail-Attribute I checked Use Mail-Package and Keep Attachments. Coding was base64

I received a mail with the csv data (A1,A2,...) as an attachment but the name still was...

payload-cc6f03303a6b11da888000096b1a234f@sap.com.bin

Thomas

PS: In this test I don't use any additional Module

stefan_grube
Active Contributor
0 Kudos

You have to set ContentDisposition in the module tab in each case. No matter if you use mail package or not, attachments or not.

Stefan

Former Member
0 Kudos

I have used the content disposition and still the filename is payload..........xml

Am I missing something else.