Showing results for 
Search instead for 
Did you mean: 
Level: Power Up

Extract email content (HTML/Plaintext) and add to Excel?



I'm using a contact form plugin on a website to collect form submissions which get emailed to me.

These emails are templated, so the subject is set, there are fields/values set all in HTML as well with values on each line


For example:


Subject: Student Applicant | James

HTML Body Preview:

<p><span>Full Name: </span><span>James</span></p>
<p><span>Email Address: </span><span></span></p>
<p><span>Phone Number: </span><span>08080808080</span></p>

Looks like:

Full Name: James

Email Address:

Phone Number: 080808080


Now, I'm using Office 365 for Business. I've setup an email rule so that subjects with the above term automatically go into the "Students" email folder.


From Flow, I've created the first step which collects an email once it arrives in that folder, which is fine.

I also have an Excel Spreadsheet in my OneDrive Business which has a table with columns: "Full Name", "Email Address" and "Phone Number".


Now here's the problem: how can I select each value from the email body?


I want to be able to select the value of "Full Name" which is "James" and make sure that can be added to the spreadsheet, but the main problem is I can't even select these values.


I was wondering if JSON Parse can help, but I have no experience in using JSON or know how the functions work in Flow. I've got experience in programming, but this is a little out of scope from what I've done before.


Any suggestions would be greatly appreciated! Thank you.

Level: Powered On

Re: Extract email content (HTML/Plaintext) and add to Excel?



I made a quick example to help you on your way. I'm still learning a lot myself, so this my be one way to get there. But there will be others. Maybe others will chip in as well.


So here is the screencap of what I came up with (I used the HTML example you posted).


- I saved your HTML example into the first variable (named 'htmltest'). The first operation I did is sort of a hack to get everything to work. I noticed the colon between the column names (like Firstname) and the name itself. I wanted to split the text on colon so that I can put everything into an array.


- I created a variable that replaced every "</span></p>" combination with a colon :


This was the expression used in the variable (add seperator): 

- Then I used "HTML to TEXT" to strip all HTML content from your form. 
- I added a compose and entered this expression to split the text on the colon seperator:


- I Initialized a variable of type Array and added the output of the Compose action.


- Then I created a variable for email adress and used the following expression to extract the mail address. You can do the same with another string variable for the name and phone number.
I named the array variable test. The 3 is the index of the mail of the student. This blogpost will help you with arrays and indexes.
I hope this helps you on your way. I did this quick and it is probably far from perfect. There will be other ways of doing this I guess. Let me know if I can do anything else for you.
If you are new be sure to check out the videos of Shane Young on Youtube. He made a few videos on Flow (and is normally going to do more).
And don't forget to watch the videos on MS Flow made by Laura Rogers. Here is her youtube channel. And here are the official docs.
Community Support Team
Community Support Team

Re: Extract email content (HTML/Plaintext) and add to Excel?

Hi @zak-elatt,


@ictmusings 's solution is able to acheive your requirement.

Have @ictmusings answered your question?


If your question haven't been solved,please share more details about the Excel table and I would offer you the special workaround with steps.


Best regards,


Level: Power Up

ur Re: Extract email content (HTML/Plaintext) and add to Excel?

Thank you! And sorry for the late reply. I've tried to understand your solution as much as I can. I can understand most of the last part I think, though I was wondering mostly how I can capture the body of the email in its HTML format and pick out each part.


And I don't clearly understand why some elements are used e.g. Compose.


Would it be alright if you expanded all the elements and showed me what each part contains so I can see how I can adapt mind and try it out, from the very beginning (Initialise Variable HTML). Also, another weird issue is that I can't find "Initialise Variable HTML" but only "Initialise Variable".


Thanks. I really appreciate your feedback! It's the closest I've gotten so far.

Level: Power Up

Re: Extract email content (HTML/Plaintext) and add to Excel?

Hi there, i'd really appreciate it if you were able to also contribute with some examples or solutions if you had any to give us any ideas!

Level: Powered On

Re: ur Re: Extract email content (HTML/Plaintext) and add to Excel?


Here are the screenshots you asked. I described everything in my previous post. These screencaps should help you further on your way. Try and follow the steps below in my example. This should help you on your way. Can you following along these 7 steps in your own Flow? If you can build this and it works, I guess you have the basis for your own solution. Can you try to copy the steps and let me know?


Example flow screenshot:



Step 1 is the trigger (manual button trigger, not important for you. The trigger for your actual flow would be an email you receive.


Step 2: part of the example. I added a variable (type string) and pasted in the example HTML you provided to work with.


Step 3: I created another string variable called "add seperator" and used the following formula: 

This is a replace formula. I took the variable named 'htmltest' (name of the variable in step 2) and replaced every occurence of </span></p> with a colon. This is important later in the example flow I quickly put together. I use the colon to split the HTML input into an array (next steps) so that we can work with the data (mail adres, name, ...) as seperate columns (like and Excel table or CSV).



Step 4: Now that the colons are in place I use the HTML to text action to remove all the extra HTML from the example (this will also strip all HTML from an email you would receive).



 Step 5: I use the compose action. The compose is just a blank "canvas" action you can use to work with text, JSON or just about anything else. Here I use it to split the output from the HTML_to_text action. 


 Look at the formula: split(body('Html_to_text'),':')


I split the text into an array using the colon (:). I added this in step 2. Thanks to the split I will now be able to extract the important information that you require, such as the mail or name.


Step 6: Here I just created a variable namd test of type 'Array'. The output of the compose action was added as the value of this variable.




Step 7: Since I now have an array with all the information you need. I made a variable for the mailadress. The value was retrieved from the array. Each part of information (name, mail, ...) in an array has a number. Using the number you can retrieve the information and put it in a variable. This variable can than be used in your flow. For instance you can write this value to an excel document or to a sharepoint list (create sharepoint list item action).


Here is the formula: variables('test')[3]




Helpful resources


New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!


Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!


Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!


Microsoft Learn

Learn how to build the business apps that you need.


Power Platform World Tour

Find out where you can attend!


Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,563)