Skip to main content

Command Palette

Search for a command to run...

Read Exchange Emails - Date range filter | UiPath

UiPath Automations

Updated
2 min read
Read Exchange Emails - Date range filter | UiPath
S

Automation Developer

In this article we will be exploring how to Read Microsoft Exchange Emails using UiPath - covering the date range filters.

Library used: UiPath.Mail.Exchange.Activities.GetExchangeMailMessages

Step 1: Install the dependency

UiPath Library: UiPath.Mail.Exchange.Activities.GetExchangeMailMessages

  • Install package: UiPath.Mail.Activities img-uipath.mail.activities.png

Step 2: Form the date filter

GetExchangeMailMessages provides below filters on date:

  • All mail messages received today > "received:today"
  • All mail messages received on 10/23/2022 > "received:10/23/2022"
  • All mail messages received since 10/23/2022 > "received: >=10/23/2022"

We'll build our own custom filter ✨ to get All mail messages received between 10/23/2022 and 10/30/2022

mailboxFilter = received: >=10/23/2022 AND received: <=10/30/2022

Step 3: Call the UiPath Activity

Calling the GetExchangeMailMessages activity with the above filter gives All mail messages received between 10/23/2022 and 10/30/2022

Note: Select Exchange Version >= 2010 img-ss-uipath.png

Bonus Step: Number of email messages > 1000

By default, the GetExchangeMailMessages activity is configured to read only 1000 emails at a time.
This value cannot be modified 🤯
How do we read large numeber of emails then?

We found out the solution: 😎

Yes, you guessed it right! 👌
We'll loop through the emails in batches of 1000 while storing the last email date.
Here's the pseudocode for better understanding:

List<MailMessage> mailboxEmails = new List<MailMessage>();
List<MailMessage> tempMailboxEmails = new List<MailMessage>(); // To store the batches
do{
    tempMailboxEmails = ReadMailMessages(mailboxFilter);
    // MailMessages are read newest first, therefore we change the higher filter limit to the last email's date
    mailboxFilter = String.Format("received: >=10/23/2022 AND received: <{0}",  tempMailboxEmails.Last.DateAsDateTime.ToString("MM/dd/yyy hh:mm:ss tt"));
    mailboxEmails = mailboxEmails.Concat(tempMailboxEmails).ToList;
} while (tempMailboxEmails.Count == 1000 );

Here's the UiPath implementation img-final-uipath.png

That's it. Emails are now read and ready to be automated. 😋

Happy Automation 🤖