Do you have a need to generate emails with PDF attachments using the Power Automate (aka Microsoft Flow) workflow engine?
Guess what! You're in luck because in this post I'll show you how to do exactly that. I'll show you how to generate a PDF document and send it via email.
At a high level, the solution is to create a HTML document containing the body of your document, save it to OneDrive, convert it to PDF and then attach the PDF document to the email.
Lets walk through it step-by-step:
1) First, add an ‘Initialise Variable' action.
2) Now we need to create a HTML version of the PDF document you'd like to generate. Append your HTML to the variable we created earlier.
I'd recommend using an online HTML editor such as jsbin.com to quickly compose the HTML document and view the edited HTML in real-time. It's much easier than editing it in Power Automate.
3) Next, add a ‘OneDrive – Create File' action to save the HTML content to a file in OneDrive. You can name the file anything you'd like. The file content should come from the variable you created earlier.
4) Add a ‘OneDrive – Convert File' action to convert your saved HTML file to PDF. Use the file Id from the previous step and select Target Type as ‘PDF'.
5) Add a ‘Outlook – Send an email' action. To attach the PDF file to the email, expand the ‘Advanced Options' section, specify a file name and set the Content field to the Content from the ‘Convert File' action.
Here is the PDF file I generated in the above example:
6) Finally, I suggest you delete the html temporary file you created earlier. Add a ‘OneDrive – Delete file' action and specify the ‘Id' of the HTML file you created earlier.
Well that's it folks. It's that simple!
If you have any tips or comments to help others, feel free to share it in the comments below.
- Solved: Set SharePoint Person Field to Null in Power Automate - 16th September 2021
- Visual Studio: Generate Class From JSON String - 17th August 2021
- Visual Studio: Show Current File in Solution Explorer - 29th July 2021