How to read Outlook email body that has both tables and text

Hi,

I have an outlook email which has some content in text format and also a table.

I need to put table in one sheet of an excel and text in another sheet of same excel.

How can I achieve this?

Save it .BodyAsHTML to a text file with an .html extension and open it in the browser. Then use UI automation to extract the table and other data needed.

Hi @postwick

How to save it as.BodyAs HTML?

It’s one of the properties of the email object you’ve retrieved with the 365 or Outlook activity. Have you gotten that far, where you have retrieved the email and have it in a variable? Then you just use Write Text File and give it yourEmailVariable.BodyAsHTML as the data to write.

I used get outlook mail message activity and save output as MailMessage List.

And then I used “save outlook mail message” and tried with both “Saye as type = .html” and “save as type = .mht”

but its throwing “Operation failed (exception from HRESULTT:)” message

@Krithi1

After getting the emails try use HTML to DataTable activities to extract the table data.

go to manage packages from market place get look for
UiPathTeam.ExtractDataTablesFromHTML.Activities this package and install it and then try your process

@Krithi1

After get outlook mail messages the output you get would be a list of mail messages

Now loop through the mailmessages in a for loop and then inside loop you will get each mail for each itwration so inside loop you can use currentitem.BodyAsHTML to get the body as html string ..which needs to be written to a text file using write text and save the file with extension .html

Now use use app/browser activity and pass the .html file and then indicate and get the table using extract datatable activity

Hope this is clear

Cheers

@Krithi1

I created a sample flow for your reference

1.After using getoutlook messages
2. Use loop to get each mail message
3.take assign activity to store the email body as html (currentMailMessage.BodyAsHtml)
4.take write text file activity to write the content in notepad and provide the extenstion ad .html
5.Use Start process activity and provide the path of that .html (4th step) then it will open in browser from there you can use table extraction to extract the table

If you find it helpful, please mark it as solution.

Happy Automation!!

That’s not what you do. You don’t save the email. You just use yourMailMessageListVariable(0).BodyAsHTML in the Write Text File activity. That’s assuming you want just the first email (index 0). If you want all of them, then you use For Each to loop through them and save them as HTML.

There is no reason to create a variable to store the value. That’s extra work for no reason. I don’t understand why so many people do that. Just put currentMailMessage.BodyAsHtml into the “Text” property of the Write Text File activity. And you’re better off using the Use Application/Browser activity to open the file in Chrome, so that then you already have the browser in-scope.

@yedukondaluaregala

I tried this and when I am trying to open “.html” file after saving, it’s opening as blank. That’s where I am stuck

Go into your browser’s extensions, to the UiPath extension, and make sure “local files” is turned on. And you shouldn’t use Start Process. You should use Use Application/Browser so then you can put activities inside it to extract the data you want.

@postwick

It’s opening as blank even when I open it manually. Not just related to automation

Open the file in Notepad and show us what’s in it.

@postwick

It’s blank even in the notepad. My apologies that I didn’t realize that earlier.

How can I fix this problem?

Show us how you’re generating the text file. Post screenshots of your activities and their properties.

@postwick

Attached is the pic. I am able to pull subject, but not the bodyhtml

First off, there’s no reason to create that htmlBody variable. You can just put currentItem.BodyAsHtml directly into the Text property of write text file. Anyway, put a Log Message before the Write Text File activity, and in the Log Message activity put currentItem.BodyAsHtml and see what it outputs.

Which activity are you using to get the emails? Is it getting more than one email?

@postwick

The log message is showing blank as well. Somehow its not able to pull the body of the email

Is it an HTML email? What do you get when you try just the body (I don’t remember the property name, might be just .body)?

Which activity are you using to get the emails? Is it getting more than one email?