How To Reverse A Received Mail List – In UiPath

Emails are something that is involved in most of the processes that we automate.

Using UiPath’s default activities we will receive the emails in FIFO order, but what if we want them to be in LIFO?

Let us see how to do that?

new_MailList = old_MailList.OrderBy(Function(x) x.Headers(“date”)).ToList

Note:
1. old_MailList is the default list that you get from the receive mail activities
2. New_MailList is the new list with mails ordered in LIFO


Example

Implementation using UiPath :

Let us implement a workflow that read emails from an account and then provides us the emails in LIFO order, instead of FIFO.

Step 1:
Drag “Get IMAP Mail Messages” activity into the design panel and populate its properties with required fields.

UiPath Reverse a mail list 1UiPath Reverse a mail list 2.PNG

Step 2:
Drag “Assign” activity into the design panel and populate it with an above-mentioned code
example: mails_List.OrderBy(Function(x) x.Headers(“date”)).ToList

UiPath Reverse a mail list 3.PNG

Step 3:
Drag “For Each” activity into the design panel and pass the above “newMailList” variable to it and change the type in the properties window to “System.Net.Mail.MailMessage

UiPath Reverse a mail list 4.PNG

Step 4:
Drag “Message Box” activity into the For Each activity and pass the “item.Subject” value into it to display the subject.

UiPath Reverse a mail list 5.PNG

Step 5:
Finally!!!

UiPath Reverse a mail list 6.PNG

Click here to download the Source Code…

Hope it has helped you…

Leave a Reply

%d bloggers like this: