How to read only a portion of an email body?

Hi Team

I need to read only a comment written under a keyword Reject in an outlook email.

Like:

Hi Team

Reject.

Price is too high.

Regards
Supplier Team

In this email body I just need to fetch the string after the keyword Reject i.e “Price is too high” not the signature of the email.

How can I achieve this ?

You can reas the body of the email and then use regex to get the part after that keyword ‘Reject’

Also If you need extract multiple lines between the Reject and the Regards keyword

strEmailBody.Split("Reject")(1).Trim.Split("Regards")(0).Trim

If there will be only one line then you can use

strEmailBody.Split("Reject")(1).Trim.Split(Environment.Newline)(0).Trim

Hi! @kkpatel

use RegEx.

Regards,
NaNi

grafik
refering to group
grafik

(?<=Reject)(?:[\.\r\n]+)(.*?\r?\n)

1 Like

@THIRU_NANI @rahulsharma

If I use regex and try to fetch the strings after Reject key word then chance is that the signature of the email will also come.

Also the signature of a user can be anything that is not our scope. That is an outside entity.

So how can it ignore the signature and only take the comment section ?

you can split using new line that will allow you to neglect the signature, as i sent it above. Or you csn use the regex too as suggested above by Peter

Make sure there are many ways to do thing but try to do it as per your scenario and with complete understanding.

Happy Automating! :v:

1 Like

Thanks @rahulsharma . let me try.

image

its not showing for me.

checked on Uipath and was working
grafik

did you try split method? screenshot shows a regex

You can use a regex or you can use the below code to split

strEmailBody.Split("Reject")(1).Trim.Split(Environment.Newline)(0).Trim

2 Likes

it seems easy to implement. I will try.

1 Like

@ppr @rahulsharma @THIRU_NANI

This is working fine if we just test with test data. But regex is not working when i run in my actual process.

That is when it is reading the actual email.

1 Like

Ok, thanks for feedback. In case of you need further help on this then required sample / further information is to share with us.