Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
gaganhl
Explorer

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




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



Image2




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



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



IFlow Design:



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




  • 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


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


Image8




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



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


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


Image11



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



Result: 



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
2 Comments
Labels in this area