How to Convert Email Attachments to PDF in Power Automate
If we know we’re bound to convert a file in our email inbox to PDF eventually, why not automate that process right away?
In Power Automate, it’s refreshingly easy to accomplish that. We can use the Office 365 Outlook connector to retrieve email attachments from a specific sender, and we can use a Cloudmersive Document Conversion connector action to make high-fidelity PDF conversions for a wide range of unique file types.
Let’s see how this works in a quick example flow.
Walkthrough: Convert email attachments to PDF
We’ll start by creating an Automated cloud flow that uses the When a new email arrives (V3) action from the Office 365 Outlook connector as its trigger action.
We’ll configure our trigger action to look for emails which 1) come from a specific sender (in this case, ourselves — to make testing easier), 2) include attachments, and 3) don’t not have attachments (we don’t want our flow to run when attachments aren’t present).
This trigger action retrieves attachment file bytes automatically, which makes our life extremely easy.
The next action in our flow will come from the Cloudmersive Document Conversion connector, which we’ll find by searching “Cloudmersive” in the Power Automate connector library.
After we click “See more” to view the full actions list, we’ll CTRL or CMD+F search for the Convert Document to PDF action.
This action works for most file types we’ll expect to encounter as email attachments — Word (DOCX), Excel (XLSX), PowerPoint (PPTX), and over 100 image formats.
To create our Document Conversion connection, we’ll first need to create a free account on the Cloudmersive website. This gives us a free API key, which allows up to 800 API calls each month with no commitments. We can then name our connection and paste our API key in the appropriate field to authorize usage (we’ll find our connection name shown at the bottom, as we can see in the below screenshot).
We’ll then pass attachment file bytes and attachment names from our trigger action as arguments for each of our request parameters.
When we do this, we’ll notice Power Automate places our PDF conversion action in a For each control. This accounts for multiple attachments in a single email.
Within that For each control, we’ll use a Create file action from the SharePoint connector to save the converted email attachments on a team site.
In our example flow, we’ve elected to use the slice() function to trim the old extension off the attachment file name and replace that with a PDF extension. The slice() function uses typical string indices; if we place our file name variable within the parentheses alongside (0, -5), we’ll lop off the “.xlsx” from an Excel file or the “.docx” from a Word document.
At this point, we’ll save our flow and run a test. Since we built an automated flow, we’ll run our test by emailing ourselves one or more attached files.
When our flow finishes running, we’ll find the PDF version of each email attachment on our SharePoint site — simple as that.
Conclusion
In this article, we learned how to convert email attachments from a specific sender to PDF and save the PDF version of that attachment in our system.
With one additional create file action, we could also save the original version of the file alongside the attachment in the same SharePoint folder. It’s easy to create useful variations of this flow thanks to the flexibility the Cloudmersive, Office 365 Outlook and SharePoint connectors offer in Power Automate.
For more quick Power Automate walkthroughs, be sure to give us a follow & check back in on our daily blog!