Converting Emails and Attachments to PDF in Power Automate

The Encodian ‘Convert to PDF‘ action supports 70+ standard file formats, including ‘MSG’, an email message. This post outlines how to convert an email message received into an Office 365 Outlook mailbox into PDF format and how to convert an email message and contained attachments into a single PDF document.

UPDATE AUG-20: Whilst this approach is still valid, our new ‘Convert Mail Message‘ action provides a much simpler solution for converting email messages to PDF. Check out this post for further details: V2: Convert Emails and Attachments to PDF in Power Automate

Convert Email (MSG) to PDF

2. Create a new ‘Automated flow.

3. Provide the following information

3.a. Flow name: Enter a relevant name/description for the Flow

3.b. Select the Office 365 Outlook ‘When a new email arrives‘ trigger action

3. c Click ‘Create.

4. Configure the Office 365 Outlook ‘When a new email arrives‘ trigger action to ensure your Flow is only triggered when required.

5. Add the ‘Export email‘ Office 365 Outlook action

5.a. Message Id: Select the ‘Message Id‘ property from the Office 365 Outlook ‘When a new email arrives‘ trigger action

6. Add the Encodian ‘Convert to PDF‘ action

6a. Filename: Enter a nominal value ensuring the msg file extension is added

6. b. File Content: Select the ‘Body’ property from the ‘Export email‘ Office 365 Outlook action

6.c. PDF Filename: Enter the name for the PDF file to be created

At this point, your email message has been converted to PDF. You simply need to add actions to your flow to do something with the PDF document; for this example, we’ll add the PDF document to a SharePoint document library.

7. Add the SharePoint ‘Create File‘ action

7.a. Site Address: Enter the location of the target SharePoint site

7. b. Folder Path: Select the target SharePoint library/folder

7.c. File Name: Select the ‘Filename‘ property from the ‘Convert to PDF‘ action

7.d. File Content: Select the ‘File Content‘ property from the ‘Convert to PDF‘ action

You can now test your Flow, noting you’ll need to ensure you send an email about the configuration you applied to the trigger action. Your email should now be converted to PDF format:

Convert Email (MSG) and Attachments to PDF

Next, we will convert the email message and any attachments to a single PDF Document.

1. Repeat ‘Convert Email (MSG) to PDF‘ steps 1 to 6

2. Add an ‘Initialize Variable‘ action

2.a. Name: Set to ‘FilesForMerge

2.b. Type: Set to ‘Array

The array variable will be used to hold the attachments (Base 64 format), which we’ll later convert and merge into a single PDF document.

3. Add an ‘Append to array variable’ action

3.a. Name: Select ‘FilesForMerge

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

3.c. Place your cursor as per the arrow and select ‘Filename‘ from the Encodian ‘Convert to PDF‘ action

3.d. Place your cursor as per the arrow and select ‘File Content‘ from the Encodian ‘Convert to PDF‘ action

4. Add an ‘Apply to each‘ control action

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

The following steps will append each attachment to the FilesForMerge variable. Images are commonplace to be embedded within emails (email signatures, for example). These embedded images are also included as attachments; therefore, the following action can be used to filter these embedded images from being treated as actual attachments.

5. Add a ‘Condition‘ action

5.a. Choose a Value: Select the ‘Attachments Name‘ property from the Office 365 Outlook ‘When a new email arrives‘ trigger action

5. b. Operator: Select ‘Starts with

5. c. Choose a Value: Enter “image0”

All embedded pictures are exposed in the attachments with an automated filename beginning ‘image0’. For example, the first image could be ‘image001.png’.

The following actions will all be added within the ‘If no’ branch:

6. Add an ‘Append to array variable‘ action

6.a. Name: Select ‘FilesForMerge

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

6. c Place your cursor as per the arrow and select ‘Attachments Name‘ from the ‘When a new email arrives’ trigger action

6.d. Place your cursor as per the arrow and select ‘Attachments Content‘ from the ‘When a new email arrives’ trigger action

7. Underneath the ‘Apply to each‘ control action, add a ‘Merge document array to PDF‘ action

7.a. PDF Filename: Enter the name for the PDF file to be created

7. b. Click the ‘Switch to input entire array‘ icon

Convert Attachment to PDF

7.c Documents: Select the ‘FilesForMerge‘ variable

Convert Attachment to PDF

At this point, your email message and its attachments will have been converted to PDF and merged into a single PDF document. You must add actions to your flow to do something with the PDF document (As before). We’ll add the PDF document to a SharePoint document library for this example.

8. Add the SharePoint ‘Create File‘ action

8.a. Site Address: Enter the location of the target SharePoint site

8.b. Folder Path: Select the target SharePoint library/folder

8. c. File Name: Select the ‘Filename‘ property from the the ‘Merge document array to PDF‘ action

8.d. File Content: Select the ‘File Content‘ property from the ‘Merge document array to PDF‘ action

Convert Attachment to PDF

You can now test your Flow, noting you’ll need to ensure you send an email about the configuration you applied to the trigger action. Your email should now be converted to PDF format:

I sent the following test email:

Convert Attachment to PDF

And the following 9-page document was created:

Convert Attachment to PDF

Troubleshooting:

Unfortunately, there seems to be a lot of variance between the ‘When a new email arrives trigger‘ actions versions relating to how the attachments are accessed, so please follow these steps should you have any issues:

Ensure that the ‘Include attachments‘ property on the ‘When a new email arrives‘ trigger action is set to ‘Yes‘, and make sure to send a new email when testing rather than using previous test data (which would still not contain the attachments if the setting has been updated).

Convert Attachment to PDF

Please also obtain the following information:

1. The version of the ‘When a new email arrives‘ trigger action, this post is using ‘V3.

2. The value of the input sent to the Encodian ‘Merge document array to PDF‘ action from the run history

Convert Attachment to PDF

Then please raise a support ticket via our support portal, and our team will advise which modifications you need to apply to your Flow.

Finally

We hope you’ve found this guide useful, and as ever, please share any feedback or comments – all are welcome!

You can find further documentation and guidance on the Encodian support portal: Merge document array to PDF.

Author
Jay Goodison

You might also be interested in.

September 9th 2024

Are Power Automate SharePoint Triggers and Actions Linked to a Single Site?

September 3rd 2024

Why Your Organization Needs a SharePoint-Based EDRM

September 3rd 2024

Choosing an EDRMS: A Comprehensive Guide

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.

Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.

Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.