How-To #5: Format Links Sent via Email in Power Automate

In this post, I will show you how to format links in the Create HTML table and Send an email actions in Power Automate.

Scenario:
When adding an link to one of the columns in the Create HTML table action, the link is expected to only show the respective title of the link with an underline, like this Link. Instead, you get something like the link displayed below. Yeah, nobody wants to see that.

<a href="https://yourdomain.sharepoint.com/sites/SiteName">Link<a/>

Solution:
For this example, I will use data from a SharePoint – Get items action since the Create HTML table action requires data from an array. Please follow the steps below:

  1. In the Create HTML table action, set the * From field to the value of the Get items action from the dynamic content window, and change the * Columns value from Automatic to Custom.
  2. Add a name for each of the header you will use along with its value. Once you get to the header that will display the link, set its value to the following expression:
concat('<a href="', item()['{Link}'], '">Link<a/>')

This expression uses the concat() function to concatenate the following strings and craft the link that will be included in the body of the email:
String 1: <a href=”
String 2: item()[‘{Link}’] (This is dynamic content from the Get items action)
String 3: “>Link

  1. In the Send an email (V2) action, we will use the Output of the Create HTML table, but rather than adding it straight up into the body of the email, we need to wrap it inside an expression using 3 replace() functions. I know you are wondering why we need to this. That’s a valid question and I will answer it below. This is what the expressions looks like:
replace(replace(replace(body('Create_HTML_table'), '&lt;a href=&quot;', '<a href="'), '&quot;&gt;', '">'), '&lt;a/&gt;', '</a>')

The reason to use this expression is due to the fact that the email body encodes certain characters, i.e. < to &lt, and they need to be converted back to the original character so the email is properly formatted. Now, let’s look at the breakdown of the expression. The first thing to point out is that expressions are executed like math, from the inside out.

  • The first replace() function that will be executed is replace(body(‘Create_HTML_table’), ‘&lt;a href=&quot;’, ‘<a href=”‘). This replace() will find &lt;a href=&quot; and it will replace it with <a href=.
  • Once the previous expression is executed, the second replace() will find &quot;&gt; and it will replace it with “>.
  • And finally, once the two previous replace() expressions are executed, the third replace() will find &lt;a/&gt and it will replace it with </a>.

The image below shows what the email actually looks like. Big difference, right?

Bonus section
To view the encoding that Outlook does to the messages, follow the steps outlined below:

  1. Open the message in a separate window and click on Actions.
  2. When the menu expands, click on Other Actions and click on View Source.
    This will open a text file in Notepad, which contains all the message information formatted in HTML.

Please give this a try and let me know in the comments section below. Thank you for reading and have a wonderful day 😀

Photo by Markus Spiske on Unsplash

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s