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

Discussion in 'Ruby' started by Damjan Rems, Sep 7, 2010.

  1. Damjan Rems

    Damjan Rems Guest

    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/.
    Damjan Rems, Sep 7, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. est
    Replies:
    1
    Views:
    609
    Diez B. Roggisch
    Feb 16, 2008
  2. Austin 7873
    Replies:
    5
    Views:
    183
    Eric Hodel
    Jan 27, 2007
  3. kazaam
    Replies:
    1
    Views:
    143
  4. Iñaki Baz Castillo
    Replies:
    1
    Views:
    153
    Iñaki Baz Castillo
    Feb 28, 2011
  5. Replies:
    8
    Views:
    1,244
    Mick White
    Apr 19, 2005
Loading...

Share This Page