Get oldest emails first

Hi,

I have a process that gets 10 emails from an inbox at at time. The inbox can have more emails in it than this, but the process is limited to 10 emails for processing purposes.

Ideally the emails would be picked up oldest first, so those that have been waiting longest are the first dealt with. However, Get Outlook Mail Messages picks up most recent first, regardless of sort order in outlook.

Can this be rectified? Perhaps with a filter? I’m afraid the assign mail messages to a sorted mail messages variable doesn’t work, as it will only sort the 10 emails it picks up.

Thanks.

Kindly have a view on this

Cheers @SoqedHozi

As I explained in my original post, I cannot use this exact approach as it gets all emails (lets say that’s 300) and this will a) take forever and b) not give me my batch of 10.

Were those mails in Unread state or are they read

@SoqedHozi

Hey @SoqedHozi,

Use “Invoke Method” Activity and write method name as “Reverse” to reverse the order of the mails received.

Thanks!

6 Likes

There could be hundreds of unread emails. They remain unread in this folder.but are moved once 10 are selected.

The order within the batch of 10 isn’t important, but those 10 should be the 10 oldest from the inbox.

@SoqedHozi

Set Top as Int32.MaxValue and then it will read all unread mails from the mail box. And then use Invoke Method activity as mentioned by @suruchi120294 to reverse mail list and read top 10 mails from that.

1 Like

If I get 300-odd emails that will take an age. How do I then cut the mailmessages to 10?

@SoqedHozi

If you want to cut it to 10 mails then you need to set Top as 10 but it will read Top 10 unread mails from mail box.

But top is set in the get outlook mail messages activity, which is prior to the invoke method.

In order for this to sort all the messages in the inbox it has to get them all, else it is only sorting the 10.

I already have top set to 10 in my get Outlook Mail Messages activity, but it gets the most recent 10. Sorting these 10 emails into date order is completely useless to me. I need the 10 most recent from the 300.

You only have two options here to make this really work, bring all mails and them order by date, or work with the filter…

So just to clarify for others seaching to solve this problem (like myself):
What you are saying is, that it is NOT possible to get a list of emails, in reverse reception date, directly from the get outlook emails activity.
You will have to get ALL emails, and then reverse the resulting list.
Is this correct?

The process time for many large emails is rather extensive, so it seams like an oversight that you cannot do this directly from the activity.

You can use the filter as i said… Will be something like this:
"[ReceivedTime] > '" + varDate.ToString("g") + "'"

Hi everyone,

Just out of curiosity, what does that (“g”) means?

Besides that, In my opinion as an overall idea, I would use not specifically the Outlook activity but a simple ‘getIMAPMailMessages’ in order to get the emails and then, yes, you will definitely have to come up with a filter based on the date to get the oldest ones as you said. I did it but in my case I needed the most recent which I know the opposite but just saying!

Regards,

You can see more here:

1 Like

I get vardate is not declared, what is this variable and where is it set?

That would be a DateTime variable with your parameter date…

I get that it’s datetime, but what parameter? Is this closer to “older than vardate” than “oldest”?

As expressed before, this does not solve the issue.

Your ‘solution’ just gets emails from a specific date and onwards.
What is discussed is getting all emails in reverse order, from mailboxes with many/large mails where getting every email takes a long time.

Getting every email and reversing the list is, as far as i can see, still the best solution, but it’s just not a very good one :slight_smile:

Sorry, i dont understand what could anyone do better than filtering, choosing a number of emails with TOP…