Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Extracting specific text from email body

(0) ShareShare
ReportReport
Posted on by 59

Hi,

 

I am trying to set up a flow to extract specific lines from the body of an email.

I currently want all information highlighted in red to point to specific columns within sharepoint:  

 

Column 1:

Short description: Suspicious Domain Registration Identified:
EXAMPLE-Uk-Plc[.]com

Description:

 

Column 2:

Domain Registered:
* EXAMPLE-Uk-Plc[.]com (34.102.136.180, Geo-location: Missouri - Kansas
City)
Date of registration:

 

Currently I have tried to only extract the text for column 1 and have come up with the following: 

 

Compose:

length(body('Html_to_text'))

Compose 2: 

add(indexOf(body('Html_to_text'),'Short Description:'),18)

Compose 3:

indexOf(body('Html_to_text'),'Description')

Compose 4: 

substring(body('Html_to_text'),outputs('Compose_2'),sub(outputs('Compose_3'),outputs('Compose_2')))

 

The I have the output rom compose 4 in the Column 1 option when creating an item in sharepoint.

 

I seem to be getting an error due to the length of the substring being too long and am unsure how to fix this. The whole email is quite lengthy so not sure if I'm breaking it down correctly and my end point isnt specific?

 

Any help would be appreciated and any more info needed please ask.

 

Thank you,

Devin

  • abm abm Profile Picture
    32,492 Most Valuable Professional on at
    Re: Extracting specific text from email body

    Could you post a screen shot of the sample email?

  • TheHobo Profile Picture
    13 on at
    Re: Extracting specific text from email body

    It appears that the formulaes used above start searching from bottom to top, which means if an email is replied to with the same table/criteria (with the old emails below), it still picks up the data in the older email. 

     

    How do I get it to search from top to bottom? 

  • TheHobo Profile Picture
    13 on at
    Re: Extracting specific text from email body

    Thankyou so much - that was very informative! Much appreciated

  • abm abm Profile Picture
    32,492 Most Valuable Professional on at
    Re: Extracting specific text from email body

    Hi  @TheHobo 

     

    Here is the video which I promised earlier. In my demo I have used the expressions individually in a compose action step which is easy to understand. Of course you can combine multiple expressions into one action step like I did here for the solution. 

     

    My tutorial link for Power Automate Expression Split(), First() & Last()

     

    Power Automate - Expressions - Split, First & Last - YouTube

     

    Thanks

     

  • abm abm Profile Picture
    32,492 Most Valuable Professional on at
    Re: Extracting specific text from email body

    Hi @TheHobo 

     

    Glad that its helpful. I will make a tutorial video about expressions and let you know.

     

    Thanks

  • TheHobo Profile Picture
    13 on at
    Re: Extracting specific text from email body

    Thanks - this worked great for me as well when looking to extract text between two different keywords. 

     

    I don't exactly understand how it works though, out of curiosity more than necessity, i'd be keen to understand what's happening in this code. (I do understand the commands individually)

     

    Thanks in advance

  • Verified answer
    abm abm Profile Picture
    32,492 Most Valuable Professional on at
    Re: Extracting specific text from email body

    Hi @Devinm501 

     

    Please see below.

     

    image.png

     

    Above expression I used is as follows:

    first(Split(last(split(outputs('Compose'),'Short description:')),'Description:'))

     

    Thanks

  • Devinm501 Profile Picture
    59 on at
    Re: Extracting specific text from email body

    Hi @abm 

     

    Apologies if i haven't explained very well. Basically i want to send the text in red (Which sits within an email) to a column in sharepoint: 

     

    Column 1:

    Short description: Suspicious Domain Registration Identified:
    EXAMPLE-Uk-Plc[.]com

    Description:

     

    the way ive tried to do this is basically separate everything from the end of the colon "Short Description:" and take all the text up until the word "Description". for some reason i can't get this working and appear to be getting an error due to the length of the substring being above 2197.

     

    does that explain any better?

     

    Thank you in advance.

  • abm abm Profile Picture
    32,492 Most Valuable Professional on at
    Re: Extracting specific text from email body

    Hi @Devinm501 

     

    Didn't understand fully about your requirement.

     

    Short description: Suspicious Domain Registration Identified:
    EXAMPLE-Uk-Plc[.]com

     

    This all in one text?

     

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1