# Attachment issue

**URL:** <https://www.ruby-forum.com/t/attachment-issue/148905>\
**Category:** Rails\
**Created:** [September 18, 2008, 7:29am UTC](https://www.ruby-forum.com/t/attachment-issue/148905 "2008-09-18T07:29:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [September 18, 2008, 7:29am UTC](https://www.ruby-forum.com/t/attachment-issue/148905/1 "2008-09-18T07:29:26Z")

</div>

Hi,

I generated the pdf file with image header (jpg log is displayed on top  
of the pdf file). I can see the logo and the datas in the pdf file  
generated. Fine. I tried to send the generated pdf in the email (using  
action mailer). Iam getting the pdf file in the email, but when I open  
the pdf file, the acrobat reader is not able to open the file.

The problem here is the action mailer is not sending the pdf file  
properly if the pdf has image inside.

This is the code:

attachment “application/pdf” do |a|  
a.body = File.read(email\_attachment)  
puts “FIle name”  
puts File.basename(email\_attachment)  
a.filename=File.basename(email\_attachment)  
end

Any idea to fix the issue?

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [September 24, 2008, 10:31am UTC](https://www.ruby-forum.com/t/attachment-issue/148905/2 "2008-09-24T10:31:15Z")

</div>

Fixed the issue

email\_attachment = “#{RAILS\_ROOT}/public/#{file\_name}”

```
  attachment "application/pdf" do |a|
    file = File.new(email_attachment, "r+b")
    a.body = file.read
    a.filename=file_name
  end
```
