Skip to content

Instantly share code, notes, and snippets.

@evenv
Created July 8, 2012 07:45
Show Gist options
  • Save evenv/3069851 to your computer and use it in GitHub Desktop.
Save evenv/3069851 to your computer and use it in GitHub Desktop.
Create a dump of all emails (title, from, to, date) from Outlook to CSV - great for statistics
require 'win32ole'
require 'CSV'
outlook = WIN32OLE.new('Outlook.Application')
m = outlook.GetNameSpace('MAPI')
def searchfolder(folder)
return if folder.defaultitemtype > 0 #only email folders
return if ["Deleted Items","Sync Issues","News Feed","RSS Feeds","Junk E-mail","SharePoint Lists"].member? folder.name
folderpath = folder.fullfolderpath.gsub("\\","-").gsub("--","")
puts folderpath
successes = 0
errors = 0
CSV.open("#{folderpath}.csv", 'w', { :col_sep => ";" }) do |writer|
writer << ["Sender","Recipient","Subject","Date"]
for item in folder.Items
begin
writer << [item.sender.name, item.recipients[1].name,item.subject,item.senton]
successes+=1
rescue
errors +=1
end
end
end
puts "SUCCESSES: #{successes} ERRORS: #{errors}"
for subfolder in folder.Folders
searchfolder(subfolder)
end
end
for folder in m.Folders
searchfolder(folder)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment