Convert an Email Message including attachments to a PDF document

mceclip7.pngThe following Flow will demonstrate how to convert an email and contained attachments into a single PDF document. 

Flow Creation Steps

1. Create a new Flow from a blank template

2.png

2. Add the ‘When a new email arrives’ Outlook trigger and configure to your requirements to specify which emails to identify and handle. 

3. Add a 'Export email' action

3a. Message Id: Insert the 'Message Id' parameter from the ‘When a new email arrives’ trigger action.

4. Add a 'Convert to PDF' action

4a. File Content: Insert the 'Body' parameter from the 'Export Email' action

4b. PDF Filename: Set to 'output.pdf'

4c. Filename: Set to 'input.msg'

5. Add an 'Initialize Variable' action

5a. Name: Set to 'FileForMerge'

5b. Type: Set to 'Array'

6. Add an 'Append to array variable' action

6a. Name: Select 'FilesForMerge'

6b. Value: Copy the following data into the action

{
"fileName": "",
"fileContent": ""
}

6.c. Place you cursor as per the arrow and select 'Filename' from the Encodian 'Convert to PDF' action

mceclip0.png

6.d. Place you cursor as per the arrow. click 'Expression' and type 'string()'

mceclip1.png

6.e. Click 'Dynamic Content' and select 'File Content' from the Encodian 'Convert to PDF' action, click 'OK'

mceclip2.png

6.f: Completed configuration:

mceclip3.png

7. Add an 'Apply to each' control action

7a. Select an output from previous steps: Insert the 'Attachments' parameter from the ‘When a new email arrives’ trigger action.

 

8. Add an 'Append to array variable' action inside the 'Apply to each' control action. 

8a. Name: Select 'FilesForMerge'

8b. Value: Copy the following data into the action

{
"fileName": "",
"fileContent": ""
}

mceclip4.png

8.c. Place you cursor as per the arrow and select 'Attachments Name' from the 'When a new email arrives' trigger action

mceclip5.png

8.d. Place you cursor as per the arrow, click 'Expression' and enter the following expression:

string(item()?['contentBytes'])

 mceclip4.png

8.e. Click 'OK'

mceclip6.png 

9. Underneath the 'Apply to each' control action, add a 'Merge document array to PDF' action

mceclip2.png

9a. PDF Filename: Set to 'EmailMessage.pdf'

9b. Click the 'Switch to input entire array' icon

9c. Documents: Insert the 'FilesForMerge' variable

The 'Merge document array to PDF' action will now return a PDF document built from the original email and it's contained attachments. It's worth noting that embedded images are contained within the email as attachments, you may wish to add a condition inside the 'Apply to each' loop to ignore specific file types or similar aligned to your specific needs.

10. Optional - Add a 'Create file' action to add the PDF document to a SharePoint library

10a > 10b: Enter relevant parameters for the chosen destination.

10c. File Name: Insert the 'Filename' parameter from the 'Merge document array to PDF' action

10d. File Content:  Insert the 'File Content' parameter from the 'Merge document array to PDF' action

11. Checkpoint: The completed flow should appear as follows

12. Execute the flow and verify results

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk