Press "Enter" to skip to content

V2: Convert Emails and Attachments to PDF in Power Automate

Ok, you got me! We released a very similar post on this exact topic early this year… so why another post? We have just released a new Power Automate action – Convert Mail Message

NOTE: At the time of writing this action is under release by Microsoft and is available in Asia and Europe (Not UK) Flow regions. The action should be available in all regions by 28th August.

This new action significantly simplifies the conversion of an email message (EML or MSG) and contained attachments to a PDF document in Power Automate. The new action also provides the capability to convert MSG or EML files which have been previously exporting and stored outside of a mailbox.

Whilst the approach outlined in our previous post is still valid, we recommend using this new action.

This post covers two examples:

  1. Converting new email messages received into a Microsoft 365 mailbox to PDF
  2. Converting existing email files to PDF

Convert a new Outlook 365 Email Message to PDF

1. Launch Power Automate – https://powerautomate.microsoft.com

2. Create a new Flow using the ‘Automated — from blank‘ option

This image has an empty alt attribute

3. Enter a name for the Flow, select the Office 365 Outlook ‘When a new email arrives (V3)‘ trigger action and click ‘Create

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

NOTE: It is imperative the ‘Include Attachments‘ property is set to ‘Yes‘ if you wish to convert the email and the attachments it contains to PDF. After you have changed this setting make sure you do not use previous test data from your run history as the historical data will still exclude attachments even after changing this setting.

5. Add the ‘Export email (V2)‘ Office 365 Outlook action

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

NOTE: The ‘Export email’ action exports emails in the EML file format and not the MSG file format.

6. Add the Encodian ‘Convert Mail Message‘ action

6.a. Filename: Enter a filename making sure the file extension is set to ‘eml‘, for example: email.eml

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

6.c Merge Attachments: Select ‘Yes

Good news, that is all you need to do! The ‘Convert Mail Message‘ action will dynamically extract the attachments and convert them to PDF. It will also convert the actual email message and then compile a single PDF document, super simple! As an example, I will add the PDF document created by the Encodian action to SharePoint.

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 the ‘Convert Mail Message‘ action

7.d. File Content: Select the ‘File Content‘ property from the the ‘Convert Mail Message‘ action

This image has an empty alt attribute

This flow is now complete and all emails that meet the trigger criteria will be converted to PDF including their contained attachments.

The resulting document will contain both the email and the attachments:

Converting an existing email file (MSG or EML) to PDF

For this quick example I will obtain and convert an MSG file from a SharePoint library and convert to PDF.

1. Create a new Flow using your desired trigger action; for this example I have simply used the manual trigger action.

2. Add a SharePoint ‘Get file properties‘ action and configure as required to target the selected EML or MSG file.

3. Add a SharePoint ‘Get file properties‘ action

3.a. Site Address: Enter the same value provided for the site address property in step #2

3.b. File Identifier: Select the ‘Identifier‘ property provided by the SharePoint ‘Get file properties‘ action

4. Add the Encodian ‘Convert Mail Message‘ action

4.a. Filename: Select the ‘File name with extension‘ property provided by the SharePoint ‘Get file properties‘ action.

4.b. File Content: Select the ‘File content‘ property provided by the SharePoint ‘Get file content‘ action.

4.c Merge Attachments: Select ‘Yes

5. Add the SharePoint ‘Create File‘ action

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

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

5.c. File Name: Select the ‘Filename‘ property from the the ‘Convert Mail Message‘ action

5.d. File Content: Select the ‘File Content‘ property from the the ‘Convert Mail Message‘ action

This image has an empty alt attribute

That’s it! The target file (MSG or EML) will be obtained from SharePoint, converted with contained attachments to a PDF file and then uploaded to SharePoint!

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: Convert Mail Message

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *