<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: outlook code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 28 Aug 2008 20:55:48 GMT</pubDate>
    <description>DZone Snippets: outlook code</description>
    <item>
      <title>Automating Outlook with Ruby: Inbox &amp; Messages</title>
      <link>http://snippets.dzone.com/posts/show/4547</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com"&gt;Ruby on Windows&lt;/a&gt; blog.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;outlook = WIN32OLE.new('Outlook.Application')&lt;br /&gt;mapi = outlook.GetNameSpace('MAPI')&lt;br /&gt;&lt;br /&gt;# Get a reference to the Inbox or other folder:&lt;br /&gt;inbox = mapi.GetDefaultFolder(6)&lt;br /&gt;personal_folders = mapi.Folders.Item('Personal Folders')&lt;br /&gt;baseball_folder = personal_folders.Folders.Item('Baseball')&lt;br /&gt;&lt;br /&gt;# Get a count of a folder's unread items:&lt;br /&gt;puts "#{inbox.UnreadItemCount} unread messages"&lt;br /&gt;&lt;br /&gt;# Iterate over messages in a folder:&lt;br /&gt;inbox.Items.each do |message|&lt;br /&gt;    # Your code here...&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# Retrieve a single message:&lt;br /&gt;first_message = inbox.Items(1)&lt;br /&gt;&lt;br /&gt;# Delete a message:&lt;br /&gt;message.Delete&lt;br /&gt;&lt;br /&gt;# Move a message to another folder:&lt;br /&gt;baseball_folder = personal_folders.Folders.Item('Baseball')&lt;br /&gt;message.Move(baseball_folder)&lt;br /&gt;&lt;br /&gt;inbox.Items.Count.downto(1) do |i|&lt;br /&gt;    message = inbox.Items(i)&lt;br /&gt;    if message.Subject =~ /cardinals/i&lt;br /&gt;        message.Move(baseball_folder)&lt;br /&gt;    end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Further details and discussion can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/08/automating-outlook-with-ruby-inbox.html"&gt;here&lt;/a&gt;.&lt;br /&gt;</description>
      <pubDate>Sat, 15 Sep 2007 12:32:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4547</guid>
      <author>dmullet (David Mullet)</author>
    </item>
    <item>
      <title>Automating Outlook with Ruby: Address Books</title>
      <link>http://snippets.dzone.com/posts/show/4473</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com"&gt;Ruby on Windows&lt;/a&gt; blog...&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;&lt;br /&gt;outlook = WIN32OLE.new('Outlook.Application')&lt;br /&gt;mapi = outlook.GetNameSpace('MAPI')&lt;br /&gt;&lt;br /&gt;#   Get list of available Address Lists&lt;br /&gt;mapi.Session.AddressLists.each do |list|&lt;br /&gt;    puts list.Name&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#   Access an Address List:&lt;br /&gt;address_list = mapi.Session.AddressLists('Contacts')&lt;br /&gt;address_list = mapi.Session.AddressLists('Personal Address Book')&lt;br /&gt;address_list = mapi.Session.AddressLists('Global Address List')&lt;br /&gt;&lt;br /&gt;#   Outlook security dialog will prompt to allow access to AddressEntries:&lt;br /&gt;address_entries = address_list.AddressEntries&lt;br /&gt;&lt;br /&gt;#   Iterate over the AddressEntries collection:&lt;br /&gt;address_entries.each do |address_entry|&lt;br /&gt;    if address_entry.Name =~ /Sinatra/&lt;br /&gt;        puts address_entry.Name, address_entry.Address&lt;br /&gt;    end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#   Search for an Address:&lt;br /&gt;address_entry = address_entries.Item("sinatra, frank")&lt;br /&gt;puts address_entry.Name&lt;br /&gt;puts address_entry.Address&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Further details can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/08/automating-outlook-with-ruby-address.html"&gt;here&lt;/a&gt;.&lt;br /&gt;</description>
      <pubDate>Wed, 29 Aug 2007 00:49:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4473</guid>
      <author>dmullet (David Mullet)</author>
    </item>
    <item>
      <title>Automating Outlook with Ruby: Contacts</title>
      <link>http://snippets.dzone.com/posts/show/4426</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com"&gt;Ruby on Windows&lt;/a&gt; blog...&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;&lt;br /&gt;outlook = WIN32OLE.new('Outlook.Application')&lt;br /&gt;mapi = outlook.GetNameSpace('MAPI')&lt;br /&gt;&lt;br /&gt;#   Create a new Contact&lt;br /&gt;contact = outlook.CreateItem(2)&lt;br /&gt;    contact.FullName = 'Stan Musial'&lt;br /&gt;    contact.BusinessTelephoneNumber = '(314)555-1234'&lt;br /&gt;    contact.Email1Address = 'stan_the_man@stlcardinals.com'&lt;br /&gt;contact.Save&lt;br /&gt;&lt;br /&gt;#   Iterate over Contact Items and extract data&lt;br /&gt;contacts = mapi.GetDefaultFolder(10).Items&lt;br /&gt;contacts.each do |contact|&lt;br /&gt;    puts contact.FullName&lt;br /&gt;    puts contact.Email1Address&lt;br /&gt;    puts contact.BusinessTelephoneNumber&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Further details can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/08/automating-outlook-with-ruby-contacts.html"&gt;here&lt;/a&gt;.&lt;br /&gt;</description>
      <pubDate>Fri, 17 Aug 2007 01:37:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4426</guid>
      <author>dmullet (David Mullet)</author>
    </item>
    <item>
      <title>Automating Outlook with Ruby: Tasks</title>
      <link>http://snippets.dzone.com/posts/show/4342</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com/"&gt;Ruby on Windows&lt;/a&gt; blog...&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;&lt;br /&gt;outlook = WIN32OLE.new('Outlook.Application')&lt;br /&gt;&lt;br /&gt;#   creating a new task&lt;br /&gt;task = outlook.CreateItem(3)&lt;br /&gt;task.Subject = 'Order Yankees Playoff Tickets'&lt;br /&gt;task.Body = 'Order first-round playoff tickets...'&lt;br /&gt;task.ReminderSet = true&lt;br /&gt;task.ReminderTime = '07/19/2007 9:00 AM'&lt;br /&gt;task.DueDate = '07/20/2007'&lt;br /&gt;task.ReminderPlaySound = true&lt;br /&gt;task.ReminderSoundFile = 'C:\Windows\Media\Ding.wav'&lt;br /&gt;task.Save&lt;br /&gt;&lt;br /&gt;#   getting tasks data&lt;br /&gt;mapi = outlook.GetNameSpace('MAPI')&lt;br /&gt;tasks = mapi.GetDefaultFolder(13)&lt;br /&gt;for task in tasks.Items.Restrict("[Status] = 'Waiting on someone else'")&lt;br /&gt;    puts task.Subject&lt;br /&gt;    puts task.DueDate&lt;br /&gt;    puts task.PercentComplete&lt;br /&gt;    puts task.Status&lt;br /&gt;    puts task.Importance&lt;br /&gt;    puts task.LastModificationTime&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#   search for and delete tasks&lt;br /&gt;for task in tasks.Items.Restrict("[Subject] = 'Order Yankees Playoff Tickets'")&lt;br /&gt;    task.Delete&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Further details can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/07/automating-outlook-with-ruby-tasks.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 21 Jul 2007 22:32:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4342</guid>
      <author>dmullet (David Mullet)</author>
    </item>
    <item>
      <title>Automating Outlook with Ruby: Calendar Appointments</title>
      <link>http://snippets.dzone.com/posts/show/4301</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com"&gt;Ruby on Windows&lt;/a&gt; blog.&lt;br /&gt;&lt;br /&gt;Use Ruby to extract appointments data from the Microsoft Outlook Calendar, delete an appointment, and create a new appointment.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;&lt;br /&gt;outlook = WIN32OLE.new('Outlook.Application')&lt;br /&gt;mapi = outlook.GetNameSpace('MAPI')&lt;br /&gt;calendar = mapi.GetDefaultFolder(9)&lt;br /&gt;&lt;br /&gt;#   reading calendar data&lt;br /&gt;data = []&lt;br /&gt;calendar.Items.each do |appointment|&lt;br /&gt;    rec = []&lt;br /&gt;    rec &lt;&lt; appointment.Subject&lt;br /&gt;    rec &lt;&lt; appointment.Location&lt;br /&gt;    rec &lt;&lt; appointment.Start&lt;br /&gt;    rec &lt;&lt; appointment.Duration&lt;br /&gt;    rec &lt;&lt; appointment.End&lt;br /&gt;    rec &lt;&lt; appointment.Body&lt;br /&gt;    data &lt;&lt; rec&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#   deleting an appointment&lt;br /&gt;calendar.Items.each do |appointment|&lt;br /&gt;    if appointment.Subject == 'Punch Bud Selig in the Nose'&lt;br /&gt;        appointment.Delete&lt;br /&gt;    end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#   creating a new appointment&lt;br /&gt;appointment = outlook.CreateItem(1)&lt;br /&gt;appointment.Start = '7/29/2007 11:00 AM'&lt;br /&gt;appointment.Duration = 300&lt;br /&gt;appointment.Subject = 'Baseball Hall of Fame Induction'&lt;br /&gt;appointment.Body = 'Tony Gwynn and Cal Ripken Jr.'&lt;br /&gt;appointment.Location = 'Cooperstown, NY'&lt;br /&gt;appointment.ReminderMinutesBeforeStart = 15&lt;br /&gt;appointment.ReminderSet = true&lt;br /&gt;appointment.Save&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Further details and discussion can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/07/automating-outlook-with-ruby-calendar.html"&gt;here&lt;/a&gt;.&lt;br /&gt;</description>
      <pubDate>Sun, 15 Jul 2007 20:06:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4301</guid>
      <author>dmullet (David Mullet)</author>
    </item>
    <item>
      <title>Automating Outlook with Ruby: Sending Email</title>
      <link>http://snippets.dzone.com/posts/show/4232</link>
      <description>From the &lt;a href="http://rubyonwindows.blogspot.com"&gt;Ruby on Windows&lt;/a&gt; blog.&lt;br /&gt;&lt;br /&gt;Here's an example of how to use Win32 OLE/COM automation to create and send an email message with Microsoft Outlook.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'win32ole'&lt;br /&gt;outlook = CreateObject('Outlook.Application')&lt;br /&gt;message = outlook.CreateItem(0)&lt;br /&gt;message.Subject = 'Subject line here'&lt;br /&gt;message.Body = 'This is the body of your message.'&lt;br /&gt;message.To = 'ted.williams@redsox.com'&lt;br /&gt;message.Attachments.Add('c:\my_folder\my_file.txt', 1)&lt;br /&gt;message.Send&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Further details can be found &lt;a href="http://rubyonwindows.blogspot.com/2007/07/automating-outlook-with-ruby-sending.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 02 Jul 2007 00:28:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4232</guid>
      <author>dmullet (David Mullet)</author>
    </item>
  </channel>
</rss>
