Over a million developers have joined DZone.

Automating Outlook With Ruby: Address Books

From the Ruby on Windows blog...

require 'win32ole'

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

#   Get list of available Address Lists
mapi.Session.AddressLists.each do |list|
    puts list.Name

#   Access an Address List:
address_list = mapi.Session.AddressLists('Contacts')
address_list = mapi.Session.AddressLists('Personal Address Book')
address_list = mapi.Session.AddressLists('Global Address List')

#   Outlook security dialog will prompt to allow access to AddressEntries:
address_entries = address_list.AddressEntries

#   Iterate over the AddressEntries collection:
address_entries.each do |address_entry|
    if address_entry.Name =~ /Sinatra/
        puts address_entry.Name, address_entry.Address

#   Search for an Address:
address_entry = address_entries.Item("sinatra, frank")
puts address_entry.Name
puts address_entry.Address

Further details can be found here.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}