From: Brian Scott Date: 2008-03-25T14:42:45+09:00 Subject: Re: Win32Ole, MAPI, and Outlook The code below processes mail from the inbox downloads the attchments then moves the mail to a subfolder. require 'win32ole' require 'yaml' #Read Configuration def _readconfig config = YAML.load_file("./config.yaml") @folder = config["config"] ["foldername"] @path = config["config"] ["pathname"] end #Setting up outlook application instance def _outapp outlook = WIN32OLE.new('Outlook.Application') mapi = outlook.GetNameSpace('MAPI') @inbox = mapi.GetDefaultFolder(6) end #Process each email and save attachment to path configured def _processor proc = @inbox.Folders.Item('#{@folder}') proc.Items.each do |message| message.Attachments.each do |attachment| filename = "#{@path}\\#{attachment.FileName}" attachment.SaveAsFile(filename) end end end _readconfig _outapp _processor Jeff Miller wrote: > Aha! > > I got it to work by using some simple exception handling. Since I hadn't > used it before (I'm somewhat new to scripting) I didn't really think of > it before. Anyway, in conclusion, I used this: > > begin > co_contacts = mapi.GetDefaultFolder(10).Folders("Company Contacts") > rescue Exception > co_contacts = mapi.GetDefaultFolder(10).Folders.Add("Company > Contacts") > end > > Thanks! > - Jeff -- Posted via http://www.ruby-forum.com/.