cancel
Showing results for 
Search instead for 
Did you mean: 

Urgent Help Required: SAP PI 7.3 File to mail Scenario Dynamic File name issue

Former Member
0 Kudos

System: SAP PI 7.3

Query: Hi Team we are working on File to Email Scenario
in which we have received incoming file with name for ex. “XYZ.csv” and in output
we need to send email with  payload as attachment. The attachment name
should be dynamic i.e. “<XYZ_timestamp>.txt (tab delimited text file)”.

We tried to use dynamic configuration through udf and we
were able to achieve the dynamic file name but the attachment was still in .xml
extension.  Please confirm how to achieve
the same.

Thanks in Advance.

Accepted Solutions (0)

Answers (4)

Answers (4)

JuanDK78
Participant
0 Kudos

Hej Pratap,

You can use the Mail Package protocol in the Mail adapter, and then create the mail content as a multipart/mixed.

You can use a UDF to create it, but I prefer XSLT.

This is and example you can use: (this one assumes the source is an IDOC the CREDAT and CRETIM fileld are used for the file name


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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:output method="xml" indent="no"/>

  <xsl:template match="*">

  <xi:Mail xmlns:xi="http://sap.com/xi/XI/Mail/30">

  <Subject>Email with Attachment</Subject>

  <From>sender@sap.com</From>

  <To>youremai@domain.com</To>

  <!--<Reply_To>String</Reply_To>-->

  <Content_Type>multipart/mixed; boundary="Abcd1234"</Content_Type>

  <!--<Content_Description></Content_Description>-->

  <!--<Content_Disposition>String</Content_Disposition>-->

  <!--<Date>2001-12-17T09:30:47Z</Date>-->

  <!--<Message_ID>String</Message_ID>-->

  <!--<X_Mailer>String</X_Mailer>-->

  <Content>

  <!-- EMAIL BOUNDARY -->

  <xsl:text>&#10;</xsl:text>

  <xsl:text>--Abcd1234</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>Content-Type: text/plain; charset=UTF-8</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>Content-Disposition: inline</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <!--EMAIL BODY-->

  <xsl:text>this is the email message body</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <!-- Attachment BOUNDARY -->

  <xsl:text>&#10;</xsl:text>

  <xsl:text>--Abcd1234</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <!--This is where you can assigne a filename to the attachment -->

  <xsl:variable name="filename">

  <xsl:value-of select="concat('File_',//CREDAT,//CRETIM,'.txt')"/>

  </xsl:variable>

  <xsl:text>Content-Type: application/xml; name=</xsl:text>

  <xsl:value-of select="$filename"/>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>Content-Disposition: attachment; filename=</xsl:text>

  <xsl:value-of select="$filename"/>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <!-- Attachment BODY -->

  <xsl:call-template name="attachment"/>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>&#10;</xsl:text>

  <xsl:text>--Abcd1234</xsl:text>

  <xsl:text>&#10;</xsl:text>

  </Content>

  </xi:Mail>

  </xsl:template>

  <xsl:template name="attachment">

  <xsl:text>This is the attachmend payload</xsl:text>

  </xsl:template>

</xsl:stylesheet>

Result:


<?xml version="1.0" encoding="UTF-8"?><xi:Mail xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xi="http://sap.com/xi/XI/Mail/30"><Subject>Email with Attachment</Subject><From>sender@sap.com</From><To>youremai@domain.com</To><Content_Type>multipart/mixed; boundary="Abcd1234"</Content_Type><Content>

--Abcd1234

Content-Type: text/plain; charset=UTF-8

Content-Disposition: inline

this is the email message body

--Abcd1234

Content-Type: application/xml; name=File_20030108140501.txt

Content-Disposition: attachment; filename=File_20030108140501.txt

This is the attachmend payload

--Abcd1234

</Content></xi:Mail>

--Abcd1234

</Content></xi:Mail>

Note:

  • all the end of line "<xsl:text>&#10;</xsl:text>" are very important, if you mess around with those the email protocol of the clients will not be able to understand the message correctly.
  • the boundary value --Abcd1234 is arbitrary, require for the email protocol: https://tools.ietf.org/html/rfc2822
Harish
Active Contributor
0 Kudos

Hi Pratap,

Please refer the below blog and wiki

Dynamic Email Attachment name for Received Mails - Process Integration - SCN Wiki

regards,

Harish

Muniyappan
Active Contributor
0 Kudos

Hi pratap,

can you paste the udf here?

looping below space also...

Regards,

Muni.

ACE-SAP
Active Contributor
0 Kudos

Hello

I'm afraid you won't get any answer as you are not posting in the appropriate area

Close that thread and ask there =>

Regards