Power Automate: Dynamically Compose HTML Emails


Power Automate can do so much more than send emails, but even so, there are plenty of processes still relying on emails. Some processes depend on emails to report workflow success or failure, others prompt for task approvals, and a few simply provide content queried from a dataset somewhere.

Figure 1 - Power Automate cloud flow with an action to Send an email.
Figure 1 – Power Automate cloud flow with an action to Send an email.

In the third scenario, it isn’t uncommon to have automations export, and email reports as HTML tables. Please, please make the table data dynamic. Often enough, flow makers hardcode their HTML values making their tables static. This may work in the short-term, but not forever because data changes:

Figure 2 - Power Automate cloud flow Send an email action with HTML table.
Figure 2 – Power Automate cloud flow Send an email action with HTML table.

One easy way to make the content more dynamic is to use Compose, which are actions useful for creating data objects much more complex than the generic string, number, and bool variables. One Compose action is enough, but for more robust tables, it’s okay to have multiple blocks available.

For this example, a Compose block is created for each possible table row. If the row is necessary, then populate its data. Otherwise, provide empty input:

Figure 3 - Power Automate cloud flow with multiple Compose action blocks.
Figure 3 – Power Automate cloud flow with multiple Compose action blocks.

In a production automation, this content should be the result of a dataset export. Here, inputs are hardcoded simply to show how things could look:

Figure 4 - Power Automate cloud flow Compose action input.
Figure 4 – Power Automate cloud flow Compose action input.

With the Compose inputs populated, their outputs can now be added to the skeleton of an HTML table in the Send an email action. Without needing to modify the email body directly, changes made to each Compose input will be reflected in the flow’s email:

Figure 5 - Power Automate cloud flow Send an email action with Compose action outputs.
Figure 5 – Power Automate cloud flow Send an email action with Compose action outputs.

Conclusion:
The Compose actions are more useful than many people realize. Here they were used to format HTML for an email, but they can be used to build JSON, XML, and other more complex data structures.

“Never be limited by other people’s limited imaginations.”

Dr. Mae Jemison

#BlackLivesMatter

Leave a comment