我想迭代Outlook收件箱而我正在使用Ruby。
我找到了一些有用的信息here,但收件箱中邮件的顺序不是由RecevedTime(项目OLE对象的属性)排序的。 GetLast方法可能会找到最新消息,但GetPrevious方法无法正常工作。
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?
如何将收件箱中的邮件从最新邮件迭代到最早的邮件?
答案 0 :(得分: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