Convert an Email Message including attachments to a PDF document

The 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: Set as follows

{
"fileName": "@{body('Convert_to_PDF')['Filename']}",
"fileContent": "@{body('Convert_to_PDF')['FileContent']}"
}

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: Set as follows

{
"fileName": "@{items('Apply_to_each')?['Name']}",
"fileContent": "@{string(items('Apply_to_each')?['ContentBytes'])}"
}

9. Add an 'Merge document array to PDF' action

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