Extract data out of body of a mail


Hi all,

I’m trying to identify how to extract the data out of this mail and store it as a variable.
I need to save “38” as variable “var_age”, “Prague” as “var_City” and so on.
The objective is to loop through all new mails with a certain subject, extract the values and write it in excel and then move the file from the inbox folder in Outlook to another folder.

Thanks in advance,
Kind regards



It is achievable. Follow the below process.

  1. Read Email based on Subject filter like: “[subject]=‘Uipath demo’” . more details here :point_right: How to filter messages in Get outlook mail messages:

  2. Use option : Unread Email

  3. You will get an out List say mailList, so you can use forEach mail in the mailList, do the below:
    … a. Use Save Mail Message : pass mail, to: “temp.mht”
    … b. Use Start Process, pass “temp.mht”. This will open the mail in the browser
    … c. Use data scraping and scrape the table data into datatable
    … d. Covert dt data into a list type using bodytableList =(From row In DataTableMail.Select() Select String.Join(",",row.ItemArray)).ToList() --> you will get List[{“Age”, “38”},{“City”, “Prague”}…]

  4. Now split to get each item: rowArray = bodytableList(0).Split(","c)
    So, you get rowArray(0) = Age, rowArray(1)= 38 and so on…

  5. Use activity Move Outlook Mail message, in: mail out, FolderName

See if this helps


Hi @nadim.warsi, thanks for your reply.
I think I’m doing something wrong at step 3.B. Can you have a look please?
When running it, i get the error “application can not be opened”.


Also, 3.d, what do you mean with “using bodytablelist”? which activity is this?



Hi @yannip,

I believe that in your Start Process activity you should add the application path i.e. Outlook.

Besides that, you will also add the full path to your .mht file.


Like @acaciomelo was saying,
Start Process is to be used to open Applications, and .mht files are not applications. You can place “temp.mht” in the app arguments though, and put the application in the first field that will be opening the file (for example, the path to Internet Explorer or Outlook)



Can you put the path that you have in the save process in the start process. That should fix this.


Hi @ClaytonM,

That indeed solved my problem. I don’t get the error anymore.
However my write line shows that the body of my mail is empty, however it is not empty in reality.

The mail of which I expect the body to be extracted:

What am I missing as it is getting the subject but not the body…



Hmmm. Can you try outputting the body of several emails in the Loop, ie outside of the If activity, so you can see everything?; maybe it’s showing a different email where the body was empty.


Hi @ClaytonM,

I tried but all the write lines for item.body.tostring are empty.
The item.subject.tostring is being treated correctly.

Can you have a look at the xaml please? It must be something easy like a parameter or a variable type that is wrong, but I can’t find it: mail test.xaml (7.3 KB)

(I just changed the account of the mailbox to not share it, but I’m using the correct account mailbox.)


It looks right to me.
You could try erasing .body and select it from the dropdown, shown in below image:

Although, that shouldn’t matter.

Only thing I can think of is that your messages don’t have a body. You should be able to tell that though by highlighting the text in the email to make sure it’s text-based. I think I would need an example of an email to look it over myself.

Another thing you can look at is the Headers which can contain other details of the message:
It’s a collection so I used String.Join to output all the items.



Hi @ClaytonM,

Thanks again for your reply. I tried your solutions (capital B for body) and joining the headers. But without result. Also, the mail is text based because when screen scraping, I do get the text.
However, when joining the headers I get a strange result as well in the output: “system.net.mime.Headercollection”.

Maybe the body problem and this have something related to each other?
Or is there another way to get the text out of the mails and storing it somewhere?



Sorry, to output the headers you need to convert the items to a string. You can use a For each loop or use the following one-liner:

String.Join("|",item.Headers.Select(Function(x) x.ToString))

I’m running out of ideas.

Hopefully, you can figure this out!



I tried it but get a different error now:

However, I am running out of ideas as well.
I found a lot of topics (also old ones) where people are having the same issue without solutions.
They can read the subject but not the body.

I also can’t use the activity “save mail attachments”.


Sorry, it’s been a while since I was using the .Headers collection. You might need .ToArray before the .Select.

You can also hardcode the Header items, like item.Headers(0).ToString and item.Headers(1).ToString and so on.

Though, I don’t think that will give you the body anyway.

Another thing to try is if you can use the Exchange server then use Get Exchange Mail Messages.



This is the result for the headers… It seems to work…
However, the body is still not working.

As you can see, there is a body in this mail: