How to read data table in mail

How do I extract the tabular data from the email body? If the email contains a structured HTML table, what activities or techniques should I use to convert it into a Data Table format in UiPath? After extracting the table data, how can I write it to an Excel file?

Hi @Sayed_Tabrez

1. Extract the Email Body

  1. Use the Get Outlook Mail Messages or Get IMAP Mail Messages activity to retrieve the email.
  • Set the appropriate filters to identify the target email (e.g., subject, sender).
  1. Loop through the retrieved emails using a For Each activity.

2. Extract the HTML Content

  • Use the MailMessage.Body property to get the email body.

3. Parse the HTML Table

To extract the table data:

  1. Use the UiPath.WebAPI.Activities.HtmlAgilityPack package or a similar method to parse the HTML.
  2. Alternatively:
  • Use the Matches activity with a regex pattern to locate the table structure.
  • Use string manipulation to extract the table rows and columns.

For a simpler approach, consider using the Extract Structured Data activity if the table is rendered in a browser during email preview.

4. Convert HTML Table to DataTable

  • Use the Html to DataTable activity from the UiPathTeam.DataTable.Activities package.
    1. Install the package via Manage Packages.
    2. Pass the HTML content to the activity to directly extract a DataTable.

5. Write the DataTable to Excel

  1. Use the Write Range activity from the UiPath.Excel.Activities package.
  • Provide the file path and sheet name.
  • Pass the extracted DataTable as input.
  1. Ensure the Excel Application Scope is used if interacting with .xls or .xlsx files.

Thanks