Extract text from email body to variables?

I need to read an email which has comma separated text value as shown in the image below and need to extract this text into separate variables?
Need help on how to do it in UiPath?


Hi @salmantahir31

Welcome to Community!!

Thanks but I have already read the body I am looking for a way to extract these codes from email and save into separate variables not the body see the image for the data I want to extract from mail body.

Hi @salmantahir31
=> Use Get Outlook Mail Messages to read the emails and store the output in a variable.
=> Use For Each to iterate throught the mail.
=> Use Assign activity and give below syntax

MailBody= currentitem.Body.ToString

=> Use another assign activity and give below syntax

Content= MailBody Split(","c)

Output datatype is Array(System.String)
=> After that you can use assign activity and give the below syntax:

strvar1= Content(0)

Content(0) will give the first value of mail body, and content(1) will give the first value and you can store the output in separate variables.

Hope it helps!!

1 Like

Hi @salmantahir31 .

Could you let us know if the Comma separated strings are dynamic are always fixed number ? (Number of values in comma separated string to be extracted separately)

If it dynamic, then you require it to be stored in an Array or as a dictionary, if not you could separate it by comma and assign each splitted value to separate variables as already shown above.

1 Like

If that’s the case then use a ASSIGN activity like this

arr_mailid = Split(yourstringvariable.ToString, “,”)

Where yourstringvariable - is a variable of type string what has that email id with comma as string
arr_mailid is a variable of type array of string

If you want to use those values from array variable one by one then pass that array variable to FOR EACH activity with type argument property as string

inside the for each activity you can call and use each email id as item.ToString

Or to save in one single variable you can get the value from array from specific position with its index number
For first value in array index position is 0 - zero

So for example to save second value from an array mention like this assign activity

stroutput = arr_mailid(1).ToString

Where 1 is the index position of second value in the array
Hope this helps

Cheers @salmantahir31

1 Like


Welcome to the community

Please try this in assign

Arrayvalues = Str.Split({","},Stringsplitoptions.None)

Let us say body is stored in str and assumption is only the value you required are present…if not please let us know we can change the expression

Arrayvalues is an array of strings which will contain each string as seprate value

To get each use the index arrayvalues(0) will give the first value similarly for all values

If you need each value in loop then pass arrayvalues as in argument in for loop activity and use item or currentitem to get the value in the current iteration

Hope this helps


The values are dynamic and not fixed number.

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