If you have too many emails, you could potentially create chunks of emails and put them into separate folders and process the folders one by one with this sort of method.
The solution posted in that link sorts the list of mailmessages AFTER the get outlook mail message activity.
According to this post, I can set the activity to just get all emails by setting the top value to negative or Int32.MaxValue but realistically, if the value is large it slows down the process considerably, so the client has a limit of 1000 to their Outlook deployment.
I’m looking for a UiPath activity that retrieves the oldest mail from the get go so we don’t just process new mails and leave old ones untouched forever.
Just for the record, this is the eventual code I got to work.
With ability to loop through all accounts in Outlook and specify which account to use.
And what folder to move to.
Probably not the most elegant as I’m still new with VB.NET.
Any suggestions are welcome.
'Init'
Dim myOlApp As New Microsoft.Office.Interop.Outlook.Application
Dim myNameSpace As Microsoft.Office.Interop.Outlook.Namespace
Dim myInbox As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim myitems As Microsoft.Office.Interop.Outlook.Items
Dim strFilter As String
Dim myAccounts As Microsoft.Office.Interop.Outlook.Stores
Dim myitem As Microsoft.Office.Interop.Outlook.MailItem
Dim myitemobject As Object
Dim myDestFolder As MAPIFolder
'Grab all accounts that exists in Outlook'
myAccounts = myOlApp.GetNamespace("MAPI").Stores
'Step through to find correct email account'
For i As Integer = 1 To myAccounts.count
Console.WriteLine(myAccounts.Item(i).DisplayName)
'Account found, check inbox'
If myAccounts.Item(i).DisplayName = "youremail@website.com"
myInbox = myAccounts.Item(i).GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
'Get all items in Inbox'
myitems = myInbox.Items
'Get oldest item'
myitemobject = myitems.GetLast
'Cast into MailItem type to enable moving'
myItem = CType(myitemobject, Microsoft.Office.Interop.Outlook.MailItem)
'Write out subject and received time for logging'
Console.WriteLine(myitem.Subject)
Console.WriteLine(myitem.CreationTime)
Console.WriteLine(myitem.SenderEmailAddress)
'Move to InProgress folder'
myDestFolder = myInbox.Folders("InProgress")
myItem.Move(myDestFolder)
End If
Next