Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8594

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

$
0
0

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

Viewing all articles
Browse latest Browse all 8594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>