Just wondering how to use the get outlook mail messages activity to filter the emails from oldest to newest. Can this be done in the filter property, example of the current filter code below:
@SQL=(urn:schemas:httpmail:subject like ‘TestJob%’ or urn:schemas:httpmail:subject like ‘%TestJob2%)’
Hello @TRX,
The Get Outlook Mail Messages activity stores the email in a MailMessage list and you can sort this list by date and time stamps in the header property.
(From email In emailMessages Order By email.Headers("Date")).ToList
The issue with doing it this way is that the process is only grabbing the top 5 (latest emails) and then processing them oldest to newest, as opposed to grabbing the bottom 5 emails in the inbox to process. The code needs to be applied at the start before the list is even filtered I feel.
Hi, It pulls the top 5 emails because the top property in the Get Outlook Mail Messages might be set to 5.
You need to set the number of emails that you want to get. You could use int32.Maxvalue if you don’t know this count. You can then sort the emails in decreasing order by date and loop 5 times to process the 5 oldest emails.
Please refer this knowledge base for more information on how to use Get Outlook Mail Messages.
Hi,
This updated example workflow should help you create the loop. As in my previous example, the workflow gets the top 5 emails and loops through each email.
You may have to modify the top and filter properties to your need. SortEmails.xaml (10.9 KB)
I’ve updated the process as per attached, for some reason it is not picking up the very last email each time upon processing (ie. it is starting from the second email from the bottom of the list). Any ideas please?
Hi,
Having a loop inside another loop using the same counter variable could have caused this issue for you. Glad to hear that using a foreach loop with an IF condition resolved this for you.
Please consider marking a post as resolution that best matches your issue description (topic title). This will help other readers find the solution for the problem in the post title. The post you marked as solution is for the issue you had with the loops and for sorting email from oldest to newest.