for Microsoft Power Automate and Azure logic apps

V2: Convert Emails and Attachments to PDF in Power Automate

By Jay Goodison

21st August 2020

V2: Convert Emails and Attachments to PDF in Power Automate

Ok, you got me! We released a similar post on this topic early this year… so why another post? We have just released a new Power Automate action – Convert Email Message which means you can convert your email and attachments to PDF with ease.

This new action significantly simplifies the conversion of an email message (EML or MSG) and contains attachments to a PDF document in Power Automate. The new act also provides the capability to convert MSG or EML files previously exported 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:

  • Converting new email messages received into a Microsoft 365 mailbox to PDF
  • Converting existing email files to PDF

Convert a new Outlook 365 Email Message to PDF

1. Launch Power Automate 

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

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

convert email to pdf

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: The ‘Include Attachments’ property must be set to ‘Yes‘ if you wish to convert the email and the attachments it contains to PDF. After changing 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, not the MSG file format.

6. Add the Encodian ‘Convert Email 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 Email Message‘ action will dynamically extract the attachments and convert them to PDF. It will also alter the email message and 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 ‘Convert Email Message‘ action

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

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

convert email to pdf

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 it to a PDF.

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

2. Add a SharePoint ‘Get file properties‘ action and configure it 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 Email 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.

convert email to pdf

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

5.d. File Content: Select the ‘File Content‘ property from the ‘Convert Email 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 Email Message

12 Comments

  1. Jenna says:

    This is working, but it creates both an .eml file and .pdf file. What should be done to delete the .eml file and keep only the .pdf?

    1. Jay Goodison says:

      Hi Jenna, the Encodian action does not create EML files… it simply returns a PDF document generated from the email message provided, which you have to pass to another Power Automate action (like SharePoint ‘Create file’). There must be something else in your flow creating the EML file.

  2. SwiPowE says:

    Hi Jay,
    this is cool stuff!

    Best

    SwiPowE

  3. Michael Murray says:

    Looking to get e-mails in landscape mode. Any way to do that with Encodian actions?

    1. Jay Goodison says:

      Hello Michael, Yes this can be done. Firstly convert the body of the HTML to a Word document using the ‘Convert Word to HTML‘ action, and then use the ‘Convert Word‘ action to set the word documents page orientation.

  4. Jared says:

    Does this work using a shared email?

    1. Jay Goodison says:

      Yes, the action is simply converting MSG & EML files… they can come from anywhere, mailboxes, SharePoint, box, etc.

  5. Andrew Barron says:

    Just wondering if it is possible to run this and exclude the “To:” and “From:” fields so you only end up with the e-mail content and not the other info at the top? Thank you

    1. Jay Goodison says:

      Hello Andrew,
      To do this you’d need to manipulate the data sent for conversion, the email is in essence just a html file. You could take the ‘Body’ output of the email and manipulate using Power Automate expressions, I’d suggest engaging our ‘Professional Services’ team to help you create a solution.
      HTH
      Encodian

Leave a comment

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