How to find specific keyword from email body?

I want to to retrieve a specific keyword from email. Like if I’m receiving an order then I want to retrieve the ordered quantity from email.
How to achieve that?

Hi,
You can use regular expression inside match activity and achieve this.
https://regexr.com/ link to test the regular expression.

Let us know if this helps,
Regards,
Pavan H

@pavanh003 I’m very beginner here so can you give any demo please.

Hi @Sameer_Sen,
This can be organizes like below:


It will check each of mail by looking for “your text”. However this is just an easy example. I suggest to check out our https://academy.uipath.com for Level 1 - Foundation Training to see how you can work with these type of projects :wink:

2 Likes

Hi

lets say for example you want to extract only numbers from the sentence then you can pass the sentence as string to matches activity and write the regular expression like this to match only the numbers
Expression: abcdefgh4523kajcbdcb4145

pattern: \d
this will give you match only numbers and then output of matchs activity will have IEnumberable of numbers.

Let us know if this helps,
Regards,
Pavan H

@Pablito Let me try this first.

1 Like

Hello,

There’s multiple possibilities for parsing the value.
Is your mail always formatted the same way ? Is it contains tables, texts, links,… ?
Can you provide us an example so we can see which solution best fits your email layout ?
So we’ll provide you the way to use regex expression to parse your value.

Regards.

Hello @Boaepa below is a sample for example:

image

It can be in text form or in table format too

@Sameer_Sen
The best way to do this is using regular expressions(Refer @pavanh003 post).

For your other query on format,
the email might be sent by multiple people and each person may send in different formats. For you to retrieve the exact data, you should know all possible templates and a key to differentiate each of these templates(This can be the sender’s email ID or any text in the email body). Once you figured the template, you have to write regex to retrieve the data you are interested in. You can write regex to just to retrieve a text value or a table of content. Both are possible.

Hope this helpful!

Hi guys im new to this and im really curious how to get this done.

does anyone have a sample on how to do this?

im trying to get a specific text from an email body.
i.e.
manager - edward

this can be found in the body of an email anywhere. the name can change but the constant word is manager.

how do i get the name using manager as the constant?

@rdperalta

  1. Store body of the mail in a string variable say ‘getText’. Then try below expression to fetch name.

getText.Substring(getText.IndexOf("manager - ")+"manager - ".Length).Split(Environment.NewLine.ToCharArray)(0)

1 Like

You are awesome Sir @lakshman … that worked…

Although the result did give me spaces before the text… ill figure out how to get rid of it… :smiley:

1 Like

@rdperalta

To remove spaces before text - StringName.TrimStart

To remove spaces after text - StringName.TrimEnd

To remove spaces before or after or in between text - StringName.Trim

1 Like

Awesome!!! i actually did the edits on excel as im used to that but this helped me with getting rid of that extra step.

Thanks :slight_smile:

1 Like

@lakshman
ak
I am facing this run time error using your solution i.e. getText.Substring(getText.IndexOf("manager - ")+"manager - ".Length).Split(Environment.NewLine.ToCharArray)(0)
Please help me with this.

@HEENA

Welcome to the UIpath Community.

Show me screenshot of your input text once.

@lakshman

Can you please tell me , how to get email body in plain text using the Get IMAP mail message activity .

@HEENA

  1. Get IMAP mail message will give you output as List of mail Messages.

  2. Then use For Each loop Activity to itreate that list.

ForEach item in mailMessages
Print item.Body.Tostring to display
body of the mail.

@lakshman
Using the same , but the result is empty message box .

@HEENA

Take screenshots of your WorkFlow and paste here. Will check once.