cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Read email content from body of the email, extract and create conditions or actions

I would love to be able to create a flow that can read the body of the email not just subject or attahcments names.  Once it can read the body of the text and find key words, extract some of this content. Identify if its a date or string and create a calendar event, etc. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Anonymous,

 

Could you please share an example about your scenario?

Do you want to extract content from body of the email?

 

I assume that the details of your incoming email as below and you want to extract the Subject and End time content from Body of the email:2.JPGI have made a test on my side and please take a try with the following workaround:

  • Add a "When a new email arrives" trigger.
  • Add a "Html to text" action, Content field set to Body dynamic content of the trigger.
  • Add a "Compose" action, Inputs set to following formula:
  • length(body('Html_to_text'))
    Add a "Compose 2" action, Inputs set to following formula:

 

add(indexOf(body('Html_to_text'),'End time'),10)
  • Add a "Compose 3" action, Inputs set to following formula:
  • substring(body('Html_to_text'),outputs('Compose_2'),sub(outputs('Compose'),outputs('Compose_2')))
    Add a "Compose 4" action, Inputs set to following formula:
  • add(indexOf(body('Html_to_text'),'Subject'),9)
    Add a "Compose 5" action, Inputs set to following formula:
  • indexOf(body('Html_to_text'),'Start time')
    Add a "Compose 6" action, Inputs set to following formula:
  • substring(body('Html_to_text'),outputs('Compose_4'),sub(outputs('Compose_5'),outputs('Compose_4')))
    Add a "Create event (V1)" action, specify Calendar id, End time field set to output of "Compose 3" action, Start time field set to following formula:
utcNow()

Subject field set to output of "Compose 6" action.

 

Image reference:3.JPG

 

4.JPG

The flow works successfully as below:5.JPG7.JPG

 

6.JPG

 

Best regards,

Kris

 

 

 

 

 

 

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

21 REPLIES 21
v-xida-msft
Community Support
Community Support

Hi @Anonymous,

 

Could you please share an example about your scenario?

Do you want to extract content from body of the email?

 

I assume that the details of your incoming email as below and you want to extract the Subject and End time content from Body of the email:2.JPGI have made a test on my side and please take a try with the following workaround:

  • Add a "When a new email arrives" trigger.
  • Add a "Html to text" action, Content field set to Body dynamic content of the trigger.
  • Add a "Compose" action, Inputs set to following formula:
  • length(body('Html_to_text'))
    Add a "Compose 2" action, Inputs set to following formula:

 

add(indexOf(body('Html_to_text'),'End time'),10)
  • Add a "Compose 3" action, Inputs set to following formula:
  • substring(body('Html_to_text'),outputs('Compose_2'),sub(outputs('Compose'),outputs('Compose_2')))
    Add a "Compose 4" action, Inputs set to following formula:
  • add(indexOf(body('Html_to_text'),'Subject'),9)
    Add a "Compose 5" action, Inputs set to following formula:
  • indexOf(body('Html_to_text'),'Start time')
    Add a "Compose 6" action, Inputs set to following formula:
  • substring(body('Html_to_text'),outputs('Compose_4'),sub(outputs('Compose_5'),outputs('Compose_4')))
    Add a "Create event (V1)" action, specify Calendar id, End time field set to output of "Compose 3" action, Start time field set to following formula:
utcNow()

Subject field set to output of "Compose 6" action.

 

Image reference:3.JPG

 

4.JPG

The flow works successfully as below:5.JPG7.JPG

 

6.JPG

 

Best regards,

Kris

 

 

 

 

 

 

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Kris,

 

My apologies for the late reply. I appreciate how creative the proposed solution is!

 

 

Thank you,

 

JP 

Anonymous
Not applicable

Thanks for the detailed desciption, I tried to run it as described above but hot the following error;

 

The string was not recognized as a valid DateTime. There is an unknown word starting at index 10. clientRequestId: c7e6674c-5d20-458b-b65a-c692c6fef136

@v-xida-msft I know this is an old thread, but I found it while looking for a solution to the same problem.

 

The difference with mine is the data I'm looking for doesn't match a nice pattern that can be easily defined by say.. add(indexof ......), 10

 

For example the email has this data:

 

Enquiry from: Firstname Lastname
Email: user@gmail.com
Phone Number: 0299999876
First Night: Thursday, 17 January 2019
Number of Nights: 2

 In each of these lines the number of characters to add to the indexof is different for each email.

 

How can I use a function to grab everything between the colon and the new line, trim it and place it in a variable?

 

I will also put this in a new thread.

Hi @Kris

 

Can you explain how to convert this example if the details repeated, how to loop through all iterations? I have a similar case, the number of items per email does very.

 

Outlook Calendar event details as below

Subject: FirstTestEvent
Start Time: 4/20/2019
End Time: 4/21/2019

 

Subject: SecondTestEvent
Start Time: 4/21/2019
End Time: 4/22/2019

 

Subject: ThirdTestEvent
Start Time: 4/22/2019
End Time: 4/23/2019

 

 

 

@HallieGUse the Split() expression to split on 'Subj' and then run the resulting array through a for-each.

Did you find any solutions to this? I'm trying to figure the same thing out. How to do this for data that might be a bit unstructured. For example, how do I grab whatever is between a "$" and ":" sign?

Hi! Did you ever find out how to do this? I'm facing the same issue.....

Anyone know how to do it as said in last posts here?

@Yanger @Brammers & @sxt173 Yes I have solved this. A long time ago I wrote a lengthy response in this thread with detailed steps and an explanation of how it all works. I spotted some typos, then did a couple of edits to fix them and it disappeared pending moderation. It has never re-appeared.

 

Probably enough time has passed to get over this immense frustration and I can re-do it. Maybe this weekend if I remember.

A somewhat abridged version of my original deleted reply:

 

Starting with this sample data:

Enquiry from: Firstname Lastname
Email: user@gmail.com
Phone Number: 0299999876
First Night: Thursday, 17 January 2019
Number of Nights: 2

To grab any of those fields in Flow you use a formula like this (example grabs the email)

 

trim(substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'Email: '),7),sub(indexOf(body('Html_to_text'),'Phone Number: '),add(indexOf(body('Html_to_text'),'Email: '),7))))
 
So I'll break it down.
trim(
	substring(
		body('Html_to_text'),
		add(
			indexOf(
				body('Html_to_text'),
				'Email: '
				),
			7),
			sub(
				indexOf(
					body('Html_to_text'),
					'Phone Number: '),
		add(
			indexOf(
				body('Html_to_text'),
				'Email: '
				        ),
			7)
		)
	)
)

The subsstring() function has 3 inputs, 1. the source string, 2. the start index, which is the number of characters into the string to start looking and 3. the length.

 

The objective therefore, is to derive 2. and 3. so we can grab the relevant text no matter how long is it.

 

So firstly we need to know how many characters into the source text to start. This is relatively easy:

add(
	indexOf(
		body('Html_to_text'),
		'Email: '
	   ),
7)

The indexOf() function finds the number of characters into a text string that a string occurs. Here we are calculating the indexOf() the string "Email: " it doesn't matter where in the original message body this occurs, indexOf() will find it and return a number.

 

Now we don't actually want the string "Email: " in the output of this expression so we now add() a number to the output of indexOf() to get the number of characters into the message body the end of "Email: " occurs. We don't calculate this dynamically; it's 7, including the space.

 

So by using indexOf() to find the place in the source string where "Email: " exists, then adding that number of characters to it, we get the point we want to start reading the email address.

 

Next we have to calculate the length of the string, for the 3rd parameter of substring():

sub(
	indexOf(
			body('Html_to_text'),
			'Phone Number: '),
	add(
		indexOf(
			body('Html_to_text'),
			'Email: '
			),
		7)
	)

To do this we use the sub() function to subtract the number we just calculated from the indexOf() the place we want to stop looking. Thus a lot (the second parameter of sub()) of the expression above is similar to the one before - calculating the number of characters into the source string that our relevant text starts.

 

The first parameter of sub() is the place where our relevant text ends - which in this case is the start of the string "Phone Number: ". We don't need to do anything complex with this because it's the start of the string we want the index of, not the end.

 

So we now have our 3 parameters for substring(), the source text, which is body('Html_to_text') in this example, the number of characters into that where we find the start of our substring and lastly length, which is calculated by subtracting the former from the number of characters into the source text where we want to stop looking.

 

Finally, in my example I've wrapped trim() around the whole thing to eliminate any trailing whitespace.

 

You could probably improve upon this by calculating the number of characters where your desired string starts in a compose action, then using that as dynamic content in the expression to simplify it a bit, instead of repeating the same formula twice in the one expression.

@WillPage I want to do exactly the same thing, I need to get an email address from the body of an email and send a new email to that address. My email account is Gmail. Where do I place the code you posted below? (totally new to flow). Obviously my first condition is "When a new email arrives" and I assume the next is where I paste your code but you don't mention what type of action to select. And I also assume my next action is to send a new email but what do I put in the "to" field there?

@pjmarcumStraight after your trigger, add an HTML to Text action and put the body of the email from the trigger in there. Next, add a Compose and put the expression there, using the output of the previous HTML to Text action in the expression.

LOL.... I'm sure this is great feedback but unfortunately way above my expertise. 🙂

Anonymous
Not applicable

Hi @v-xida-msft ,

 

My case is a little different and I want to extract the email address after the From: of a forwarded email. Does the number of Compose change and do I need to change the code for them? 

 

vradley_0-1597937641125.png

 

 

 

Hello Team,

 

Any recommendations on trying to extract say a reference number that will start with CX but could be anywhere in the email body on any new email. there is no set template and can come through anytime. 

 

Regards, 

 

Andy 

WillPage
Memorable Member
Memorable Member

If the reference number is always the same number of characters then you would use substring like this. Assume it's a 8 character reference including the CX (and you want to keep the CX in the substring)

substring(body('HTML_to_Text'),indexOf(body('HTML_to_Text'),'CX'),8)

 

..where body('HTML_to_Text') is the output of your HTML to text conversion action.

 

A few pitfalls: This will always find the first instance of CX in the text. If you have many then it's more complicated finding the right one.

 

Thankfully there are few ordinary words with cx in them but there's a small chance of picking that up too.

 

Another method you could use is this:

 

Split(body('HTML_to_Text'),'CX') to create an array of strings that start at each instance of CX (without the actual CX bit at the front), with the first item being the start of the whole input..

 

Now if your ref numbers are always 8 characters including CX you add a Select action, click the little icon to change from key-value input to JSON input and do this in the expression editor concat('CX',substring(item(),0,6).

 

The resulting array will be a list of possible reference numbers. Not knowing what they look like I can't advise how to filter out invalid ones (the first one will almost certainly be invalid) but at this point you can do further processing to get rid on any bogus elements in the array and hone down to the valid one(s).

 

Kris,

I have a similar situation that I need help on. In my case, the fields of the form input are displayed in the email like this (with the relevant information I want to extract in the line or lines below the field header):

 

fscutaro_1-1673270184763.png

The problem I've encountered is that in some cases, the requestor can fill out more than one item per field and that adds lines to the email like this:

fscutaro_3-1673270299074.png

I’ve been able to create a flow that converts the HTML to text and then returns data by extracting data by line. The issue is that there are some conditional fields in the form and that adds lines to the email. There is also the ability to select multiple responses for certain fields and that also adds lines to the email. When that happens the result is that the extract is incorrect.


My thought is to search the field names and have Power Automate select all the text between names (terms), after I’ve converted the email body to text from HTML.


So my questions are; 1) Is that a sound approach and 2) what expressions should I use for that action?

Please let me know your thoughts. Thanks.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (707)