Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   How to embed picture into e-mail with mail gem (any lib) (http://www.velocityreviews.com/forums/t864314-how-to-embed-picture-into-e-mail-with-mail-gem-any-lib.html)

Damjan Rems 09-07-2010 11:03 AM

How to embed picture into e-mail with mail gem (any lib)
 
And the picture will show (not as attachment) on gmail or outlook
client. This is what I am doing(according to what I have found on net),
but all I get is a square which tells where picture should be shown but
it isn't.
-----------------
require 'net/smtp'
require 'rubygems'
require 'mail'

c = File.open('mygif.gif','rb') { |f| f.read }
mail = Mail.new
mail.subject = 'Some subject'
mail.attachments['mygif.gif'] = c
id = mail.attachments.first.content_id.gsub(/<|>/,'')

html_part = Mail::Part.new do
content_type 'text/html; charset=UTF8'
body "<p><img width=\"800\" height=\"600\" src=\"cid: #{id}\"></p>"
alt=\"somename\">"
end
mail.html_part = html_part

send_mail mail.to_s
-----------------

I even tried this but it isn't working neither.
body "<img width=\"800\" height=\"600\"
src=\"data:image/gif;base64,#{Base64.b64encode(c)}\"


by
TheR
--
Posted via http://www.ruby-forum.com/.



All times are GMT. The time now is 10:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.