As part of our ongoing series about using the Muhimbi PDF Converter API in combination with Microsoft Flow, Logic Apps and PowerApps, we present an example about how to automatically convert the body of incoming emails to PDF, and archive the results in DropBox.
Earlier today we were contacted by a Flow user who wanted to convert incoming emails to PDF. Now, the Muhimbi PDF Converter actually comes with an awesome email to PDF converter, but it expects an MSG or EML file as the input. Unfortunately the various email based triggers that currently ship with Flow (Outlook for Office 365, Outlook.com, Gmail) do not provide files in this format. Instead, they expose the message Body, Subject, From, To, Attachments etc.
Update 10/10/2018: Exporting an email as an EML file, which can then be fed into our Convert Action,is now available for Outlook 365. When using Outlooks 365, readthis 3rd party blog postinstead and skip the information provided below.
Even though the MSG file is not available, all the individual elements are. We managed to ‘knock up’ a functional email to PDF converter using Flow in absolute no-time. You may want to customise it further by using the Compose Action to add the subject, from and to fields to the body before sending it into the PDF Converter. You can even use our Merge documents Action to convert the attachments and merge them all, alongside the main body, into a single PDF.
Similar to our other examples, this Flow is just a starting point. You can use a different email service as a trigger (outlook.com, Outlook for Office 365) and send the generated PDF to SharePoint, OneDrive, Google Drive, email, you name it.
From a high level, the Flow works as follows:
The full Flow can be found below. It is automatically created by the Flow Template named Convert Email to PDF and archive in DropBox. After selecting the template make sure the following fields are changed:
- DropBox Output folder (for HTML emails): The DropBox folder to write the PDF files to.
- DropBox Output folder (for Text emails): The DropBox folder to write the PDF files to.
The Flow itself is relatively straight-forward, but there is one complication. Email may appear to be a simple format, but content can be represented in HTML format, Plain Text and even RTF. Depending on the format we need to send the body either to the HTML converter or the Text converter. In this Flow we use a simple and dirty trick, which is to check if either ‘<html’, ‘<p’ or ‘<br’ can be found in the email body. If it is then we send it to the HTML converter, otherwise the Text converter.
That is all there is to it. I left this flow running by mistake and when I came in the next day DropBox had synced dozens of emails to my local PC. They looked brilliantly though when opened in a PDF reader.
If you have any questions about extending this template, or implementing it in your environment, then please leave a message below or contact our friendly support desk. We are here to help.