DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 23 posts at DZone. View Full User Profile

Automating Outlook With Ruby: Contacts

08.16.2007
| 3710 views |
  • submit to reddit
        From the <a href="http://rubyonwindows.blogspot.com">Ruby on Windows</a> blog...
require 'win32ole'

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

#   Create a new Contact
contact = outlook.CreateItem(2)
    contact.FullName = 'Stan Musial'
    contact.BusinessTelephoneNumber = '(314)555-1234'
    contact.Email1Address = 'stan_the_man@stlcardinals.com'
contact.Save

#   Iterate over Contact Items and extract data
contacts = mapi.GetDefaultFolder(10).Items
contacts.each do |contact|
    puts contact.FullName
    puts contact.Email1Address
    puts contact.BusinessTelephoneNumber
end
Further details can be found <a href="http://rubyonwindows.blogspot.com/2007/08/automating-outlook-with-ruby-contacts.html">here</a>.