Created
July 13, 2011 21:04
-
-
Save octosteve/1081330 to your computer and use it in GitHub Desktop.
Embedding Images in Outlook Messages With Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32ole' | |
email = "[email protected]" | |
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