Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created July 13, 2011 21:04
Show Gist options
  • Save octosteve/1081330 to your computer and use it in GitHub Desktop.
Save octosteve/1081330 to your computer and use it in GitHub Desktop.
Embedding Images in Outlook Messages With Ruby
require 'win32ole'
email = "someone@anyplace.net"
image1 = "/home/user/images/image1.jpg"
image2 = "/home/user/images/image2.jpg"
outlook = WIN32OLE.new('Outlook.Application')
message = outlook.CreateItem(0)
message.To = email
message.Subject = "My Subject"
message.attachments.add(image1)
message.attachments.add(image2)
1.upto(message.attachments.count) do |index|
message.attachments(index).PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001E", "image/jpeg")
message.attachments(index).PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", message.attachments(index).filename)
end
message.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", true)
message.HTMLBody = <<-HTML
<img src="cid:#{image1}" />
Fill in with delicious HTML
<img src="cid:#{image2}" />
HTML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment