Friday, August 3, 2007

Ruby Script to send email using outlook

Downloaded Latest version of Ruby and install it: http://rubyforge.org/frs/?group_id=167 -- Download 1.8.6-25)

Save the followig script as Mail.rb

require 'win32ole'
outlook = WIN32OLE.new('Outlook.Application')
message = outlook.CreateItem(0)
message.Subject = 'Subject test'
message.Body = 'This is the body of your message.'
message.To = 'xyz@abc.com'
message.Attachments.Add('c:\test.xls', 1)
message.Send

Double click on it to run the script.This will automatically send email with the attachment test.xls

No comments: