Over a million developers have joined DZone.

Outlook - Messages To Archive

·
Deleted Items = mapi.GetDefaultFolder(3)
Outbox = mapi.GetDefaultFolder(4)
Sent Mail = mapi.GetDefaultFolder(5)
Inbox = mapi.GetDefaultFolder(6)
Calendar = mapi.GetDefaultFolder(9)
Contacts = mapi.GetDefaultFolder(10)
Journal = mapi.GetDefaultFolder(11)
Notes = mapi.GetDefaultFolder(12)
Tasks = mapi.GetDefaultFolder(13)
Drafts = mapi.GetDefaultFolder(16)
All Public Folders = mapi.GetDefaultFolder(18)
Conflicts = mapi.GetDefaultFolder(19)
SyncIssues = mapi.GetDefaultFolder(20)
Local Failures = mapi.GetDefaultFolder(21)
Server Failures = mapi.GetDefaultFolder(22)
Junk = mapi.GetDefaultFolder(23)


#move all 2010 messages from inbox to personal folders "Old Inbox 2010"

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

#personal folders
personal_folders = mapi.Folders.Item('Personal_folder')

#subfolder old inbox 2010 under personal folders
old_inbox = personal_folders.Folders.Item('Old Inbox 2011')

#all items that are older than 1.1.2011 move to archive
inbox.Items.Count.downto(1) do |i|
         message = inbox.Items(i)
         if message.CreationTime < "2011/01/01 00:00:00"
		message.Move(old_inbox)
         end
end
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}