How do I read specific texts from an Email body?

Email Body :-

Dear ABC,

Approval Type - Internal Transfer Request
Purpose Of Transfer - Normal Transfer
Internal Transfer Number - ITRAP-000897525
Date of Submission - 24 June 2023
Originator - ABC
Internal Transfer Subject - From Commercial to Inspection Room

Thanks and Regards,
XYZ.

I want all the below mentioned values in separate variables.

Internal Transfer Request
Normal Transfer
ITRAP-000897525
24 June 2023
ABC
From Commercial to Inspection Room

How do I achieve this ?

Providing an xaml file will be much helpful.

Thanks,
uio.

Hi @uio

Hoping that you can get to the email and then to its body though UiPath Activities
You can use Regex to retrieve the highlighted text in you message, or split string operations.

For example:

With Regex: (?=Type - ).*+(?=\s)

image

You can use Split function if you’ll be getting a standard format, i.e. purpose type would always be coming after approval type, else go ahead with regex.
With Split function:

MailBody.Split({“Approval Type”},StringSplitOptions.None)(1).Split({“Purpose”},StringSplitOptions.None)(0).Trim(" -".ToCharArray)

Happy Automation! :smiley:

Hi @uio

You can use the following RegEx patterns to extract the desired data:

For Approval Type:

approvalType = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Approval Type - (.+)").ToString

For Purpose of Transfer:

purposeofTransfer = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Purpose Of Transfer - (.+)").ToString

For Internal Transfer Number:

internalTransferNumber = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Internal Transfer Number - (.+)").ToString

For Date of Submission:

dateofSubmission = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Date of Submission - (.+)").ToString

For Originator:

originator = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Originator - (.+)").ToString

For Internal Transfer Subject:

internalTransferSubject = System.Text.RegularExpressions.Regex.Match(emailBodyString,"Internal Transfer Subject - (.+)").ToString

image

image

image

image

Hope this helps,
Best Regards.

@uio

Please try the attached XAML. You’ll get an ouput like this:

image

RegexExtraction.xaml (9.2 KB)

Notice that I didn’t include the space character after the “-” in each label and added a .Trim at the end to make sure the code still works even when the input has inconsistent formatting.

Hope it works for you! Thanks

Thanks for providing a xaml file.

I tried reading mails from my inbox folder with output as “mail_body”.

When assigning it, I’m getting error.

Please do help me with this.

@uio

The Get Outlook Mail Messages activity results into a List type of variable. Lists can be looped through with the For Each activity (see attached XAML).

image

image

RegexExtraction.xaml (12.2 KB)

Make sure to update the Folder property before you try to run:
image

Access the body of the email by using currentItem.Body.ToString inside the loop where currentItem is the iteration variable for each mail message.

Thanks!

Hi @uio ,

You are directly displaying the the Mail messages List, instead you need to loop on every mail and then extract body for a particular email. Refer screenshot:

Thank you so much for your efforts.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.