I need to extract email address from inbox and insert into an excel file

Hi everyone, I would like help/guidance in creating a sequence for collating all the email addresses from my Outlook inbox and compiling them in a new Excel file.

Thank you for your help!

@mnurhaikal

LLM helped me to write this but it’s validated by me.

To collate all email addresses from your Outlook inbox and compile them into an Excel file using UiPath Studio, follow this step-by-step guide:

Prerequisites

  1. Make sure you have the UiPath.Mail.Activities package installed.

  2. Ensure that you have access to Outlook and it’s configured on your system.

Steps

  1. Set Up Variables

mailMessages (Type: List) — Stores the list of emails retrieved from Outlook.

emailAddresses (Type: List) — Stores the extracted email addresses.

outputDataTable (Type: DataTable) — Stores the email addresses for Excel output.

  1. Retrieve Emails from Outlook

Use the Get Outlook Mail Messages activity:

MailFolder: “Inbox”

Top: Specify the number of emails to retrieve (or leave it empty for all emails).

Output: mailMessages

  1. Initialize the Data Table

Use the Build Data Table activity:

Add a single column named “Email Address” of type String.

Assign the output to outputDataTable.

  1. Extract Email Addresses

Use a For Each activity to loop through mailMessages:

Type Argument: System.Net.Mail.MailMessage

Inside the loop, add the following steps:

4.1. Get Sender Email Address:

Use an Assign activity:

To: senderEmail

Value: item.From.Address

Use an If activity to check if the email is not already in the list:

Condition: Not emailAddresses.Contains(senderEmail)

If True, use Add to Collection to add senderEmail to emailAddresses.

4.2. Get Email Addresses from Recipients:

Loop through item.To and item.CC using nested For Each activities:

For each recipient, use an Assign activity:

To: recipientEmail

Value: recipient.Address

Check if recipientEmail is not already in the list and add it using Add to Collection.

  1. Populate the Data Table

Use another For Each activity to loop through emailAddresses:

Inside the loop, use the Add Data Row activity:

ArrayRow: { email }

DataTable: outputDataTable

  1. Write to Excel

Use the Write Range activity (from Excel activities):

DataTable: outputDataTable

File Path: Specify the path where you want to save the Excel file.

Sheet Name: “EmailAddresses”

Add Headers: Check this option.

Complete Workflow Summary

  1. Get Outlook Mail Messages → Retrieve emails.

  2. Build Data Table → Initialize the DataTable.

  3. For Each (mailMessages) → Extract email addresses:

Get sender, recipients, and CC addresses.

  1. For Each (emailAddresses) → Populate the DataTable.

  2. Write Range → Export to Excel.

This workflow will help you create an Excel file with all unique email addresses from your Outlook inbox. If you encounter any issues or need more specific help, let me know!

@mnurhaikal

Use get mail or get outlook any mail activity

Now you have list of mails with you

You can use generate datatable activity and give string as String.Join(Environment.NewLine,mails.Select(function(x) x.FromEmail.Address)) and select cav parsing…it would give you a datatable

Now use write range to write datatable to excel

Function remains same but this prt x.FromEmail.Address might differ based on what email activity you use…adjust accordingly

Cheers

Hi Thank you for the guide but I have a few queries.

Firstly,
“mailMessages (Type: List) — Stores the list of emails retrieved from Outlook.
emailAddresses (Type: List) — Stores the extracted email addresses.”

I cant seem to find the Type: List.

Secondly,
My Get Outlook Mail Message Activity does not work properly and after i keyed in Output: mailMessages, there is an error.

Thanks!

I did this sequence. It seems correct but my Excel sheet did not display any email address. It is just a blank sheet:




This is the excel sheet after the bot runs:

@mnurhaikal

First check if the for loop is running…looks like no mails are retreived

Cheers