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 / extracting text from e...
Power Automate
Answered

extracting text from email with no structure

(0) ShareShare
ReportReport
Posted on by 6

Hi

 

I am try to extract three things from a email into a list, i was wondering if some could guide me how to do it ?

 

All want to do is take the order number from email,name of person,their problem. 

 

Thanks

 

 

Email address 

Name 

Order 

Problem 

 

I have tried to use : 

to grab the text BEFORE the # symbol :    first(split(body('Html_to_text'),'#'))

to grab the text AFTER the # symbol :    last(split(body('Html_to_text'),'#'))

 

but this doesn't seem to work i have even tried to convert into lines but i am struggling.

 

 

Example of an email  1

 

 

Hi,

We have received the below from a customer. Please can you confirm what actions need to be taken so we can relay this to the customer or if able please can you contact the customer directly.

Firstname Lastname
###@gmail.com 
W12433311-1M-V

----------------------------------------------

!*** Firstname Lastname was not signed in when this comment was submitted. Learn more ***!

Firstname Lastname, 14 Dec 2022, 09:42

I still haven’t received my order can you pls update me

 â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ  Conversation ID: 42581102-8a97-11ed-9d64-7d7cb637a4b4 42581102-8a97-11ed-9d64-7d7cb637a4b4 49be6de

 

 

 

Example 2 

 

Hi,

We have received the below from a customer. Please can you confirm what actions need to be taken so we can relay this to the customer or if able please can you contact the customer directly.

Firstname Lastname
#####@yahoo.co.uk 
W12617455-2M-V

----------------------------------------------

!*** Firstname Lastname was not signed in when this comment was submitted. Learn more ***!

Firstname Lastname, 2 Jan 2023, 05:36

I ordered this item weeks ago and it still hasn't arrived. I would like to be refunded please.

------------------
Submitted from:

 â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ  Conversation ID: 48d7040b-8a7c-11ed-a8ee-96d2e547bdbc 48d7040b-8a7c-11ed-a8ee-96d2e547bdbc 49be6de

Categories:
I have the same question (0)
  • Verified answer
    v-liwei-msft Profile Picture
    on at

    Hi @um09 

     

    Based on the first email example, I made a test for your reference:
    1. Email address:

    split(trim(last(split(first(split(outputs('Html_to_text')?['body'],'-----')),'directly.'))),decodeUriComponent('%0A'))[1]


    2. Name:

    split(trim(last(split(first(split(outputs('Html_to_text')?['body'],'-----')),'directly.'))),decodeUriComponent('%0A'))[0]


    3. Order number:

    split(trim(last(split(first(split(outputs('Html_to_text')?['body'],'-----')),'directly.'))),decodeUriComponent('%0A'))[2]


    4. For customer questions:
    Add an additional compose, enter two carriage returns in it

    vliweimsft_0-1672986735222.png

    then use the formula

    split(first(split(outputs('Html_to_text')?['body'],'Conversation ID')),outputs('Compose_5'))[add(length(split(first(split(outputs('Html_to_text')?['body'],'Conversation ID')),outputs('Compose_5'))),-2)]

     

    Best Regards,

    Levi

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Assuming the initial body of the email is the same (except for the data you're trying to retrieve), you can try the following.

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_1-1672990070448.png

     

    When a new email arrives is what you already have.

    grantjenkins_2-1672990104067.png

     

    Html to text takes in the body of the email as you have already done.

    grantjenkins_3-1672990147187.png

     

    Filter array extracts the data into an array, removing any empty lines. The expressions used are:

    //Body (input)
    split(outputs('Html_to_text')?['body'], decodeUriComponent('%0A'))
    
    //Condition
    trim(item())

    grantjenkins_4-1672990317076.png

     

    We can then extract out the Name, Email, and Order Number using the following expressions:

    //Name
    trim(body('Filter_array')[4])
    
    //Email
    trim(body('Filter_array')[5])
    
    //Order Number
    trim(body('Filter_array')[6])

     

    In my example flow, I've created three variables to hold the values.

    grantjenkins_5-1672990423462.png

     

    Or, if you just wanted an object with the values, we could create a variable of type object with the following.

    {
     "Name": @{trim(body('Filter_array')[4])},
     "Email": @{trim(body('Filter_array')[5])},
     "Order Number": @{trim(body('Filter_array')[6])}
    }

    grantjenkins_6-1672990507879.png

     

    This would give us the following output.

    grantjenkins_7-1672990589745.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Another option is to use XPath expressions. This is assuming the email address will always contain #@

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_8-1672994176195.png

     

    XML is a Compose that takes in the data from Html to text, split by new line and converts it to XML. The expression used is:

    xml(json(concat('{"root": { value:', split(outputs('Html_to_text')?['body'], decodeUriComponent('%0A')), '}}')))

     

    We can then use the following expressions to get the Name, Email, and Order Number.

    //Name
    xpath(outputs('XML'), 'string(//root/value[contains(text(), "#@")]/preceding-sibling::value[1]/text())')
    
    //Email
    xpath(outputs('XML'), 'string(//root/value[contains(text(), "#@")]/text())')
    
    //Order Number
    xpath(outputs('XML'), 'string(//root/value[contains(text(), "#@")]/following-sibling::value[1]/text())')

     

    In my example flow, I've created three variables to hold the values.

    grantjenkins_9-1672994367386.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

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 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard