cancel
Showing results for 
Search instead for 
Did you mean: 
NiloferA

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.

NiloferA_0-1654015887725.png

 

  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’

NiloferA_1-1654015887727.png

 

 

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

NiloferA_2-1654015887729.png

 

  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

NiloferA_3-1654015887734.png

 

  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.

NiloferA_4-1654015887736.png

 

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 -

<a href="@{outputs('Compose_4')}">Click here</a><br>

 

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

NiloferA_5-1654015887737.png

 

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

NiloferA_6-1654015887737.png

 

 

  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”

NiloferA_7-1654015887738.png

 

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

NiloferA_8-1654015887739.png

 

  1. Add a compose with this expression

NiloferA_9-1654015887740.png

 

split(split(items('Apply_to_each'), 'width&#58;')[1], 'px')[0]

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

NiloferA_10-1654015887740.png

 

width=@{outputs('Compose_9')} alt

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

NiloferA_11-1654015887741.png

 

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

NiloferA_12-1654015887742.png

 

replace(variables('String'), items('Apply_to_each'), outputs('Compose_10'))

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

NiloferA_13-1654015887742.png

 

  1. Increment the Counter variable by 1

NiloferA_14-1654015887743.png

 

  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

NiloferA_15-1654015887743.png

 

split(items('Apply_to_each'), '"')[0]

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

NiloferA_16-1654015887744.png

 

  1. Add Compose 3 and configure it as follows

NiloferA_17-1654015887744.png

 

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

NiloferA_18-1654015887745.png

 

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

NiloferA_19-1654015887746.png

 

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

NiloferA_20-1654015887746.png

 

{

“Name”:”Compose 3 Output”,

“ContentBytes”:Body from above step

}

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

NiloferA_21-1654015887747.png

 

 

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

NiloferA_22-1654015887747.png

 

  1. replace(replace(variables('String'),'<br>',''), '/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

NiloferA_23-1654015887749.png

 

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

NiloferA_24-1654015887750.png

 

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/