Skip to Content
Technical Articles
Author's profile photo Gagan HL

Send PDF as Mail Attachment in SAP CPI with Mail Adapter Configuration

Introduction: 

This blog will guide you through a seamless process of sending a PDF as an attachment in a project, complete with customised parameters. This essential functionality plays a pivotal role in communication via email.

Scenario:

Imagine scenarios in a SuccessFactors project, where sending a PDF attachment is crucial or transmitting sales orders and invoices. This configuration is widely employed in various mailing scenarios, highlighting its significance in communication.

Solution:

So here in this scenario lets envision a seamless process where we craft an email dynamically, encompassing subject, recipient address, mail body, and a PDF file. The beauty lies in the ability to send these dynamic details without the need for manual adjustments in both the CPI iFlow and mail adapter configurations.

Rather than sending the PDF as a standalone entity, we opt for a more sophisticated approach. We elegantly dispatch not only the PDF but also the accompanying elements such as recipient address, subject, and mail body as integral components of the email.

So let’s dive into to the flow.

Prerequisite:

So here the way we transport the PDF is using the Base 64 encoded data of the PDF. Basically this allows you to transport binary over protocols.

We can get the Base64 encoded data of a PDF using CPI. Please find below a simple flow to get a Base64 encoded data.

Image1

Image1

  • HTTPS Adapter: Use HTTPS Adapter as we sent a PDF file through Postman and retrieve the Base64 encoded data.

Image2

Image2

  • Base64 Encode: Now add a Base64 Encode to the flow as shown in the image below.

Image3

Image3

  • Postman: Now send the PDF which you want in Base64 encoded format in Postman as Body > Binary as shown in the below image.

Image4

Image4

IFlow Design:

Image5

Image5

  • HTTPS Adapter: In this flow we are using HTTPS Adapter as we send the data through Postman.

 

  • JSON to XML Converter: Using JSON to XML Converter to convert the input JSON data given through Postman to desired XML format.

Image6

Image6

  • Content Modifier: We will declare properties to store the data that we need to dynamically set as the subject, recipient address, mail body, PDF name and also the Base64 encoded data(refer image4).

Image7

Image7

In Message Body we use the stored Base64 encoded data by using the expression ${property.pdf}

Image8

Image8

  • Base64 Decoder: By using Base64 Decode we decode the Base64 encoded data of the PDF to be mailed.

Image9

Image9

  • Mail Adapter: For the mail adapter Configuration follow the below link.

https://help.sap.com/docs/cloud-integration/sap-cloud-integration/configure-mail-receiver-adapter

Here in this flow we have used the Connection configuration shown in the image below.

Image10

Image10

The Processing configuration of the Mail Adapter is shown in the image below.

Image11

Image11

Image12

Image12

  • Input Payload in Postman:  The input payload is given below.
{
"emailId" : "ABC@gmail.com",
"pdfname" : "Abc",
"pdf" : "USE THE BASE64 ENCODED DATA HERE",
"subject": "PDF as Attachment",
"body": "Hello,

I hope this email finds you well. Please find the PDF file in the attachment.

Thanks,
Name"
}

Here in “emailId” -> Use the recipient mail address and in “pdf” -> Use the Base64 Encoded Data (refer Image4)

Image13

Image13

Result: 

Image14

Image14

In conclusion, I believe that this blog post has aimed to deliver essential knowledge into the way of dynamically sending PDFs as email attachments by seamlessly incorporating subject lines, recipient addresses, and mail bodies in the Mail Adapter. Hence we eliminate the need for constant configuration adjustments.

 

Thanks and Regards,

Gagan H L

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sufiyan Sayed
      Sufiyan Sayed

      Hi Gagan,

      Thanks for sharing such a great blog. I just want to know that why are you using 2 Integration flows? we can decode it in the same iflow.

      Also if we want to use 2 Iflows we can connect it with process direct and therefore we don't have to trigger the postman 2nd time for the 2nd iflow.

      So is there any specific reason which I'm missing here? Please let me know.

      Thanks & regards,

      Sufiyan.

      Author's profile photo Gagan HL
      Gagan HL
      Blog Post Author

      Hi Sufiyan Sayed ,

      The first iFlow is used to get the Base64 encoded data of a PDF using CPI, it is not a mandatory step. You can use any other platform to get the Base64 encoded data.

      Thanks and Regards,

      Gagan H L