From: gregarican Date: 2005-09-28T04:31:43+09:00 Subject: Re: Outlook calendar Here's a final go at something. If you create a calendar called Vacation Calendar out in the Public Folders in your Outlook/Exchange environment and populate some entries this should work without a hitch. Replace the MAPI session name with an Outlook profile on your client PC that's running the Ruby script. Let me know how it goes! ---------------------------- require 'win32ole' # these are some CDO property tag constants CDOPROPSETID1= "0220060000000000C000000000000046" CDOAPPT_STARTDATE = "0x820D" CDOAPPT_ENDDATE = "0x820E" CDOPR_BODY = 0x1000001F # this starts a MAPI session with Outlook/Exchange @session = WIN32OLE.new('Mapi.Session') @session.logon('Greg Kujawa') # replace with your Outlook profile name # this pages through the top level Outlook folders to find the Public Folders object publicFolders = String.new recordCount = @session.InfoStores.count recordCount.times { |i| publicFolders = @session.InfoStores.Item(i+1).RootFolder.Folders if @session.InfoStores.Item(i+1).name == "Public Folders" } # this pages through the next level of Outlook folders to find the All Public Folders object allPublicFolders = String.new recordCount = publicFolders.count recordCount.times { |i| allPublicFolders = publicFolders.Item(i+1).Folders if publicFolders.Item(i+1).name == "All Public Folders" } # this pages through the final level of Outlook folders to find the Vacation Calendar object vacationCalendar = String.new recordCount = allPublicFolders.count recordCount.times { |i| vacationCalendar = allPublicFolders.Item(i+1).messages if allPublicFolders.Item(i+1).name == "Vacation Calendar" } # now that we have a Vacation Calendar object we iterate through all items in it, # reporting back some property values recordCount = vacationCalendar.count recordCount.times { |i| begin # get into the habit of rescuing MAPI/CDO reads, as items with unassigned values raise runtime errors puts "The calendar event is "+vacationCalendar.Item(i+1).Subject puts "The start date is "+vacationCalendar.Item(i+1).Fields.Item("{#{CDOPROPSETID1}}#{CDOAPPT_STARTDATE}").Value.to_s puts "The end date is "+vacationCalendar.Item(i+1).Fields.Item("{#{CDOPROPSETID1}}#{CDOAPPT_ENDDATE}").Value.to_s puts "The calendar detail is "+vacationCalendar.Item(i+1).Fields.Item(CDOPR_BODY).Value.to_s rescue # here we just essentially report back nothing puts "I'm blank!\n" end }