Because it is not the same result
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.
Ok, you can do better with a little code:
Only need to import the namespace Microsoft.Exchange.WebServices.Data that is already present in your project with uipath mail package.
Thanks for the code, for those of us with less coding experience 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
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
Also you can optimize your code to readmails.take(10) if you want
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