How to embed picture into e-mail with mail gem (any lib)

D

Damjan Rems

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top