0

I'd like to iterate Outlook Inbox and I'm with Ruby.

I've found some useful info here, but the order of message in Inbox is not ordered by RecevedTime(Property for Item OLE object). GetLast method may find the latest message but GetPrevious method does not work as I expected.

require 'win32ole'

outlook = WIN32OLE.new('Outlook.Application')
mapi    = outlook.GetNameSpace('MAPI')
inbox   = mapi.GetDefaultFolder(6)

inbox.Items.GetLast # return the latest message, maybe
inbox.Items.GetPrevious # return nil object and then, what's this method for?
inbox.Items.Sort('ReceivedTime')    # is this right usage? if so, what's next?

How can I iterate messages in Inbox from the latest to the oldest?

1 Answer 1

0
require 'win32ole'

ol = WIN32OLE.new('Outlook.Application')
class OC; end
WIN32OLE.const_load(ol, OC)

mapi = ol.GetNameSpace("MAPI")
inbox = mapi.GetDefaultFolder(OC::OlFolderInbox)
items = inbox.items
items.sort('ReceivedTime', OC::OlAscending)

items.getfirst
items.getnext

items.getlast
items.getprevious

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.