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

**URL:** <https://www.ruby-forum.com/t/how-to-embed-picture-into-e-mail-with-mail-gem-any-lib/194579>\
**Category:** Ruby\
**Created:** [September 7, 2010, 1:03pm UTC](https://www.ruby-forum.com/t/how-to-embed-picture-into-e-mail-with-mail-gem-any-lib/194579 "2010-09-07T13:03:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [September 7, 2010, 1:03pm UTC](https://www.ruby-forum.com/t/how-to-embed-picture-into-e-mail-with-mail-gem-any-lib/194579/1 "2010-09-07T13:03:20Z")

</div>

## 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 “

\<img width=“800” height=“600” src=“cid: #{id}”\>

”  
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©}”

by  
TheR
