# Inline attachment

**URL:** <https://www.ruby-forum.com/t/inline-attachment/182215>\
**Category:** Rails\
**Created:** [January 25, 2010, 9:43am UTC](https://www.ruby-forum.com/t/inline-attachment/182215 "2010-01-25T09:43:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [January 25, 2010, 9:43am UTC](https://www.ruby-forum.com/t/inline-attachment/182215/1 "2010-01-25T09:43:36Z")

</div>

Hi All

I followed this link [http://blog.thoughtobject.com/2007/05/26/5/](http://blog.thoughtobject.com/2007/05/26/5/) and  
installed inline-attachment for attaching image files in my mails.

But when i add this  
@cid = Time.now.to\_f.to\_s + “removed\_email\_address@domain.invalid”

inline\_attachment :content\_type =\> “image/png”,  
:body =\>  
File.read(“#{RAILS\_ROOT}/public/images/lightbulb.png”),  
:filename =\> “lightbulb.png”,  
:cid =\> “\<#{@cid}\>”  
in model emailer.rb  
I get only this image in the mail  
ie,even if i add some static content to html.erb as well as display some  
of the dynamic data which i pass through,  
recipients to\_addr  
from “removed\_email\_address@domain.invalid”  
subject subj  
body :cid =\> @cid, :message =\> msg, :name =\> to\_name  
content\_type “text/html”  
and use  
 ![]()  
in the html.erb file,

I get only the image without any text.

But in case,I remove this inline\_attachment part  
inline\_attachment :content\_type =\> “image/png”,  
:body =\>  
File.read(“#{RAILS\_ROOT}/public/images/lightbulb.png”),  
:filename =\> “lightbulb.png”,  
:cid =\> “\<#{@cid}\>”

and try without ![]()  
in the html.erb file, the text are all coming .

I am not able to figure out whats wrong.Kindly help me in cracking this.

Thanks In Advance.

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [February 22, 2010, 11:13am UTC](https://www.ruby-forum.com/t/inline-attachment/182215/2 "2010-02-22T11:13:43Z")

</div>

hi,  
try this, it is working fine.  
for inline attachment…  
attachment :content\_type =\> “application/html”,  
:filename =\> filename,  
:body =\> File.read(filename)

```
@cid='removed_email_address@domain.invalid'
image_path = "#{RAILS_ROOT}/public/images/logo.jpg"
f=File.open(image_path,'rb')
inline_attachment :content_type => "image/jpg",
                  :body => f.read,
                  :filename => "logo.jpg",
                  :cid => '<#{@cid}>'

```

body[:cid] = @cid

for display image in email  
try this  
 ![]()

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 26, 2010, 12:34pm UTC](https://www.ruby-forum.com/t/inline-attachment/182215/3 "2010-03-26T12:34:21Z")

</div>

Saboor wrote:

> hi,  
> try this, it is working fine.  
> for inline attachment…  
> attachment :content\_type =\> “application/html”,  
> :filename =\> filename,  
> :body =\> File.read(filename)
> 
> ```
> @cid='removed_email_address@domain.invalid'
> image_path = "#{RAILS_ROOT}/public/images/logo.jpg"
> f=File.open(image_path,'rb')
> inline_attachment :content_type => "image/jpg",
> :body => f.read,
> :filename => "logo.jpg",
> :cid => '<#{@cid}>'
> 
> ```
> 
> body[:cid] = @cid
> 
> for display image in email  
> try this  
> ![]()

Hai ,  
This is a code i have uses to send an email with inline and  
attachment .  
I have one .png file .  
I used above code to send an email . But i got an error  
index 91697 out of string error

The code is  
a=ActionMailer::Base.smtp\_settings = { :address =\> ‘ip address’,  
:port =\> 25 ,  
:domain =\> ‘domain name’}

```
            @cid = "removed_email_address@domain.invalid"
            from 'from address'
            recipients 'to address'
            subject 'testing Mail '

```

attachment :content\_type =\> “image/png”,  
:body =\>  
File.read("#{RAILS\_ROOT}/public/images/rails.png"),  
:filename =\> “rails.png”

image\_path = “#{RAILS\_ROOT}/public/images/rails.png”  
f=File.open(image\_path,‘rb’)

```
            inline_attachment :content_type => "image/png",
            :body => f.read ,
            :filename => "rails.png",
            :cid => "<#{@cid}>"

```

body[:cid] = @cid .
