Power Community

Power Community

Send SharePoint Page HTML Content in Outlook Email

Here, I have a scenario where we are using and customizing SharePoint Pages in classic mode on SharePoint Online and want to view all the content in a well formatted email. I have the Publishing Feature enabled for my SharePoint Site and upload all my images in Images Library first and then refer them on the Page.

Please find below the steps to create the Flow,

  1. Start with When a file is created trigger
  2. Initialize a string variable to hold links to the Videos if any are embedded on the page
  3. Now let’s work on getting the SharePoint Page Body content from Pages Library by adding “Send an http request to SharePoint” action and configure it as follows. This is going to return all the Fields including the ones which store the HTML for the SharePoint Page consisting of Text, Images and Videos.


  1. The above will return a lot of fields, the ones we are going to run manipulations on are
    1. ‘PublishingPageContent’ which holds the HTML for the page


Getting Video Links and recreating HTML for our email

  1. We will focus on gathering the links to Videos if, any. Videos are embedded as iframe tags in the HTML Content, so let’s use split expression to divide the entire HTML string into an array divided by the keyword ‘iframe’


split(body(‘Send_an_HTTP_request_to_SharePoint’)[‘d’][‘PublishingPageContent’], ‘iframe’)

  1. Above expression will return an array split at the points where the phrase ‘iframe’ was found, we want to capture only the items where the links to videos are found in this array. To do this, add a Filter Array action and configure it as shown below


  1. If the Filter Array expression indeed returns any output, we want to further create some HTML to nicely display them in an email, so we will add some HTML content in the variable initialized before


  1. Next, we want to extract the link part only from the HTML strings in the array returned in Step 5 and use them in recreated HTML for our email. With this extraction of Video links and recreating the HTML to display them in our email is complete.


Expression used in Compose in the diagram above –

replace(substring(split(item(), ‘src=”‘)[1], 0, indexOf(split(item(), ‘src=”‘)[1], ‘”‘)), ‘:’, ‘:’)

Expression used in Append to String variable in the diagram above –

Click here

Getting Images, their width and recreating HTML for our email

  1. Next, we will focus on gathering the links to images and their widths to maintain the same size in the email, but first let’s initialize following variables whose uses are described in later steps
    1. An Array Variable
    2. A Final String variable of type String, set the value as body(‘Send_an_HTTP_request_to_SharePoint_2’)[‘d’][‘PublishingPageContent’]
    3. A Counter Variable of type Integer with value 0
    4. A Width Variable of type String
  2. Add a Compose action and Split the PublishingPageConent from step 3 by ‘’PublishingImages/” to get an array of strings


split(body(‘Send_an_HTTP_request_to_SharePoint_2’)[‘d’][‘PublishingPageContent’], ‘PublishingImages/’)

  1. Add a Filter Array action and pass the output from the previous step and add the below condition. This is to capture only the strings which consist of images


  1. Add an Apply to Each action, pass the Array output from previous step, inside this action add the below ones
  2. We need to check if the images have any applied width on the page, to do this, we need to check if the current string item consists of the phrase “width”


contains(items(‘Apply_to_each’), ‘width’)

  1. If this is true, we want to extract the number assigned to width attribute and run below manipulation operations and replace the image tags with our manipulated string in the Final String variable


  1. Add a compose with this expression


split(split(items(‘Apply_to_each’), ‘width:’)[1], ‘px’)[0]

  1. Recreate the HTML with the number fetched from above, set the Width variable to below HTML string


width=@{outputs(‘Compose_9’)} alt

  1. Replace the current item’s “alt” with “Width” variable value and store it in Compose


replace(items(‘Apply_to_each’), ‘alt’, variables(‘Width’))

  1. Replace the current item available in the Final String variable with above output and store it in Compose


replace(variables(‘String’), items(‘Apply_to_each’), outputs(‘Compose_10’))

  1. Finally Set the Final String Variable with Output from above step


  1. Increment the Counter variable by 1


  1. From here on, I am going to number the Compose actions to understand where their outputs are being used.
  2. Add a Compose 1 and split it by ‘”’ (double quote) to extract the name of the image


split(items(‘Apply_to_each’), ‘”‘)[0]

  1. Add Compose 2 to concat your relative SharePoint Library URL (hardcoded) with the Image Compose 1 output


  1. Add Compose 3 and configure it as follows


  1. Add Compose 4 and use it to replace instances of Compose 2 found in Final String variable with Compose 3


  1. Add Get file content action and pass the below URL


  1. /Library Name/Compose 1 Output
  1. Add Append to Array Variable, pass Array Variable here and configure it as below



“Name”:”Compose 3 Output”,

“ContentBytes”:Body from above step


  1. Finally Set the Final String variable with Compose 4 output


Convert relative URLs to absolute for them to work in Outlook

  1. Step out of the Apply to each now, and add a Compose action to replace breaks with emtry string and relative URLs with absolute ones


  1. replace(replace(variables(‘String’),’
    ‘,”), ‘/sites’, ‘https://yourdomain.sharepoint.com/sites‘)

Send Email

  1. Create the HTML Format of your choice here I am just adding a table and injecting my HTML content the way I want them to be displayed in the email


  1. Click on the advanced options, and in the Attachments field switch to text mode and add the Array variable


This post was originally published on this site

- Advertisement -spot_img


Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Maximizing Your Power Platform Solution’s Reach: Essential Performance Considerations for Optimal Efficiency

Hi Folks, This blog post is all about performance considerations for your Power Platform CE Projects and how you can...

More Articles Like This

- Advertisement -spot_img