web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Extract email content ...
Power Automate
Unanswered

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

(1) ShareShare
ReportReport
Posted on by 6

Hello,

 

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:

<div>
<p><span>Full Name: </span><span>James</span></p>
<p><span>Email Address: </span><span>james@gmail.com</span></p>
<p><span>Phone Number: </span><span>08080808080</span></p>
</div>

Looks like:

Full Name: James

Email Address: james@gmail.com

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.

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    Hi,

     

    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).

    Screencap1.png

    - 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): 

    replace(variables('htmltest'),'</span></p>',':')
     
    - 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:
    split(body('Html_to_text'),':')
    screencap3.png

     

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

     

     
    - 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.
     
    expression: 
    variables('test')[3]
     
    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.
  • v-yuazh-msft Profile Picture
    on at

    Hi @zak-elatt,

     

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

    Have @Anonymous 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,

    Alice

  • zak-elatt Profile Picture
    6 on at

    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.

  • zak-elatt Profile Picture
    6 on at

    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!

  • Community Power Platform Member Profile Picture
    on at

    Hi,

    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:

    Screencap1.png

     

    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.

    screencap2.png

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

    replace(variables('htmltest'),'</span></p>',':')
     
    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).

     

    screencap3.png

    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).

     

     screencap4.png

     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.

    screencap5.png

    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.

     

     

    screencap6.png

    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]

     

     screencap7.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard