Get oldest emails first

Because it is not the same result :slight_smile:
You are giving a solution to a problem saying “how do it get emails that are older than a specific date”, but the question is “How do i get the bottom x emails for large mail boxes (meaning: without getting all emails and reversing the list)”

Example: Mail box contains emails from 1-10 in that order.
Request: Get emails 10-5 in a list in that order
Current best solution: get all emails (1-10) and revers the order (10-1), then take top 5 (10-5). This solution is very slow on large mailboxes, as getting all emails take a lot of time.
Your solution: get emails from a sepefic date = don’t know what we get, but we get SOME email in the wrong order, like 1-3 or 1-7.

This is a workaround. But you could find it useful.
GetOldestEmailFirst.xaml (9.6 KB)

Cheers

2 Likes

That looks cool. i’ll try it out. Thank you @J0ska

It only works for Exchange mail server indeed.

Cheers

Ok, you can do better with a little code:
image
Only need to import the namespace Microsoft.Exchange.WebServices.Data that is already present in your project with uipath mail package.

1 Like

Thanks for the code, for those of us with less coding experience :wink: will this pull the oldest 10 emails from a specified folder and output as a system.net.mail.mailmessage?

Dim iv As ItemView = New ItemView(10)

If I change the value from 10 to 1, will that just get the oldest email? Thanks in advance!

that is the point yes, but i haven’t tested it so i don’t know if it works.
I convinced my users that we didn’t need to start with the oldest mails, as long as we got back to them later :slight_smile:

I had a similar scenario in my process, what I did was-

Read maximum number of emails using getoutlookmailmessage activity

reverse those mails using invoke method “Reverse”

using For Each loop - Type argument system.net.mail.mailmessage

and in Value field mailmessage output variable.getrange

ie.
Screenshot from 2021-01-09 22-30-16

0 will get the bottom email (Last email in inbox)

10 is the range of emails to read

I hope this helps… :slight_smile:

1 Like

thank you for your suggestion, but if you read the thread you will see that we are trying to avoid this method, as we are dealing with large mailboxes with large emails, where the reverse method takes a loooooong time to run :slight_smile:

Also you can optimize your code to readmails.take(10) if you want :slight_smile:

I can confirm that it does work, but it gives you an exchange email message variable which doesn’t work with other uipath email activities, but it is possible to use the exchange web services api that this uses to do things like moving the email to a different folder

1 Like