Accessing Outlook folders, other than Inbox

Hi,

This works great for processing my Outlook inbox:

------8<----------------8<-------------
require ‘win32ole’

Open a MAPI session

session = WIN32OLE.new(‘Mapi.session’)
session.logon(‘MS Exchange Settings’)

Get the INBOX

messages = session.inbox.messages
messages.each do |m|
# do something
end

-----8<---------------8<-----------------

but if I change ‘inbox’ to ‘contacts’ or ‘calendar’, for instance, I get

C:\rubycode\outlook_helper.rb:8:in `method_missing’: Fail(GetIDsOfNames)
Unknown property or method : contacts (WIN32OLERuntimeError)
HRESULT error code:0x80020006
Unknown name

Can someone tell me how to access other Outlook folders using win32ole?

Thanks in advance for any help,
Barry

Barry,

This is a fairly ugly way to do it, but it works for me:

    require 'win32ole'

    o = WIN32OLE.new("Outlook.Application")

    ns = o.GetNamespace("MAPI")
    cf = ns.GetDefaultFolder(9)
    e = o.Explorers.Add(cf, 2)

    items = cf.Items
    (1 .. items.Count).each { |n|
      item = items.Item(n)
      puts "#{item.Start}: #{item.Subject}"
    }

    # Shut down Outlook process.
    e.Close

This iterates over all the appointments you have defined
in your Calendar.

This may not be helpful, but it might give you some
ideas ...

-- Dossy

···

On 2002.10.08, SHULTZ,BARRY (HP-Israel,ex1) <barry_shultz@isr.exch.hp.com> wrote:

Can someone tell me how to access other Outlook folders using win32ole?

--
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)