DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 23 posts at DZone. View Full User Profile

Automating Outlook With Ruby: Tasks

07.21.2007
| 3459 views |
  • submit to reddit
        From the <a href="http://rubyonwindows.blogspot.com/">Ruby on Windows</a> blog...
require 'win32ole'

outlook = WIN32OLE.new('Outlook.Application')

#   creating a new task
task = outlook.CreateItem(3)
task.Subject = 'Order Yankees Playoff Tickets'
task.Body = 'Order first-round playoff tickets...'
task.ReminderSet = true
task.ReminderTime = '07/19/2007 9:00 AM'
task.DueDate = '07/20/2007'
task.ReminderPlaySound = true
task.ReminderSoundFile = 'C:\Windows\Media\Ding.wav'
task.Save

#   getting tasks data
mapi = outlook.GetNameSpace('MAPI')
tasks = mapi.GetDefaultFolder(13)
for task in tasks.Items.Restrict("[Status] = 'Waiting on someone else'")
    puts task.Subject
    puts task.DueDate
    puts task.PercentComplete
    puts task.Status
    puts task.Importance
    puts task.LastModificationTime
end

#   search for and delete tasks
for task in tasks.Items.Restrict("[Subject] = 'Order Yankees Playoff Tickets'")
    task.Delete
end
Further details can be found <a href="http://rubyonwindows.blogspot.com/2007/07/automating-outlook-with-ruby-tasks.html">here</a>.