Outlook - extract body text as variables


I’m trying to extract three variables from an email body. I’m able to log into the mailbox successfully, and load the message, but I’m unsure how to parse the text into variables that will then be used as variables in a web app workflow.

The email body simply contains:


I’d like to set the variables with the values after the colon. For example, set variable ProjectNumber = ProjectX, etc.

Thanks for guidance on how to best accomplish this within Studio. Current workflow to get emails:

—once after getting the list of mails from mail activity named as list_mails
—now use a FOR EACH activity and pass that list variable as input and change the type argument as System.Net.Mail.MailMessage
—inside the loop use a ASSIGN activity like this
list_string = item.Body.ToString.Split(Environment.NewLine.ToArray()).ToList()

Where list_string is a variable of type System.Collections.Generix.List(of string) with default value as New List(of string) defined in the variable panel

—now inside this for each loop use another FOR EACH activity and pass the above variable list_string as input and change the type argument as string the property panel and change the variable name from item to line

—inside this inner for each loop use a assign activity like this
str_TaskName = IF(line.ToString.Contains(“TaskName”), Split(line.ToString,”;”)(1).ToString.Trim, String.Empty)

Similarly use two more for other two values to be obtained
str_ProjectNumber = IF(line.ToString.Contains(“ProjectNumber”), Split(line.ToString,”;”)(1).ToString.Trim, String.Empty)

str_VendorName = IF(line.ToString.Contains(“VendorName”), Split(line.ToString,”;”)(1).ToString.Trim, String.Empty)

Where str_TaskName, str_ProjectNumber, str_VendorName are string variables which will hold the value we need

Cheers @aheber


@Palaniyappan, thanks so much for the help. I believe I’m getting close with this information, but have a couple of questions. On your first list, I believe I’m having an issue with not correctly understanding the point of, “once after getting the list of mails from mail activity named as list_mails.” I used this variable in the Output → Result of the Get Mail function, but this generates the following error. I’m not sure if that was the intended place for this variable name, and if so, what type it should be configured as to remove the error:

Kindly use a GET IMAP MAIL ACTIVITY or GET POP3 MAIL ACTIVITY where we can create a variable in the output property named list_mails

For configuring either of these two activities with gmail


Cheers @aheber

@Palaniyappan, I think I’m almost there. Switching to IMAP allowed me to save the body to a variable. The email is being read, as it’s changed from unread to read. No errors are reported, however the data is not being assigned to the string variables.

In the attached screen shot, I’m breaking after the strings should have been assigned to the three variables. The email is getting read, and marked as read. Also in the screen shot to the right is the text of the email.

Also, while debugging and looking at the body of the email that’s returned, it’s being returned in HTML format, which might be causing a parsing issue?


Do one thing. Assign that body of the mail to one string variable and say “mailBody”. And then below expressions to get required data.

       str_ProjectNumber = mailBody.Substring(mailBody..IndexOf("ProjectNumber:")+"ProjectNumber:".Length).Split(Environment.NewLine.ToCharArray)(0)

        str_TaskName = mailBody.Substring(mailBody..IndexOf("TaskName:")+"TaskName:".Length).Split(Environment.NewLine.ToCharArray)(0)

Same way try other one also.


Hi @lakshman. This is my first UiPath project, so I’m not sure specifically which steps you’re suggesting I replace, and with which ‘Activity.’


Remove that ForEach loop here and also show me screenshot of your flow once. So that i can check and tell you.


Is all mails contains body of the mail in same format ?

If yes then try below steps.

  1. Assign Get IMAP Mail Message output to mailMessages variable and note that it should be of type List of Mail Messages.

  2. And then use ForEach loop to iterate one by one mail.

       ForEach item in mailMessages
           mailBody = item.Body.Tostring
            And then try above mentioned expressions in my previous posts.

Note: Use Assign activity and write those expressions.

And yes, all emails are the exact same format.

1 Like


You wrote expression like this: mailBody…IndexOf. Because of that it’s showing an error. It should be mailBody.IndexOf

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