To create a Power Automation Flow, browse to Microsoft Power Automate | Microsoft Power Platform
Create an Automated Cloud Flow
Click on the "Create" menu item
Click "Automated Cloud Flow"
Search for "Email" and select "When a new email arrives (V3)" and click "Create"
When a new email arrives (V3)
Set up the connection to your email inbox, open the advanced options and then proceed to enter the filtering details of the particular email you wish to have this trigger on. For our example we used the subject filter "Training"
Condition
This step can be skipped and you can proceed to create your actions etc, but for this example, in the body of the email, we are looking for a simple keyword throughout the whole body of the email, "Failed"
Click "+ New Step"
Search for "Condition" and select
For our example, we used the "Body" email dynamic content, but others can be used as well like "Subject"
If yes
When the condition of "Failed" is found, the following section of code is initiated in actions
If no
When the condition of "Failed" is not found, the following section of code is initiated in actions
Action
HTML to text (preview)
To begin, add an action named "Html to text (preview)" by clicking "Add an action" and searching for "HTML"
Convert the body of the email into text by selecting the "Body" in "Dynamic Content"
Compose
Add an action named "Compose" by clicking "Add an action" and searching for "Compose"
Rename the Compose action to an easily identifiable variable like "EmployeeName"
To input the expression, select "Inputs" and then select "Expression"
The following code is broken up into 3 essential parts:
Part 1 & 3 is to determine the first index, the number is the length of the title → add(indexOf(body('Html_to_text'),'Employee full name:'),19)
Part 2 is to determine the second index, this is where the text extraction will stop → sub(indexOf(body('Html_to_text'),'System generated information:')
trim(substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Employee full name:'),19),sub(indexOf(body('Html_to_text'),'System generated information:'),add(indexOf(body('Html_to_text'),'Employee full name:'),19))))
For a dynamic text that utilises a previous compose action, you can use for example → concat(' for ',outputs('EmployeeName')) or outputs('EmployeeName')
trim(substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Process step:'),13),sub(indexOf(body('Html_to_text'),concat(' for ',outputs('EmployeeName'))),add(indexOf(body('Html_to_text'),'Process step:'),13))))
It is recommended to copy and paste the code into notepad to make your modifications before inserting into your flow expression field due to the lack of space the field provides.
This will then output the text in between the two indexes
If there is another variable or text you wish to extract from the email, begin the process again by adding another "Compose" and repeating the step again.