Over a million developers have joined DZone.

Automating Outlook With Ruby: Contacts

·
From the Ruby on Windows 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 here.
Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}