Created
July 8, 2012 07:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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