# Pdf attachment to be in the same name

**URL:** <https://www.ruby-forum.com/t/pdf-attachment-to-be-in-the-same-name/147396>\
**Category:** Rails\
**Created:** [September 1, 2008, 12:07pm UTC](https://www.ruby-forum.com/t/pdf-attachment-to-be-in-the-same-name/147396 "2008-09-01T12:07:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [September 1, 2008, 12:07pm UTC](https://www.ruby-forum.com/t/pdf-attachment-to-be-in-the-same-name/147396/1 "2008-09-01T12:07:39Z")

</div>

Hi

I am sending email with pdf attachment using ActionMailer. But when I am  
receiving it, it is received in a different file name like ATT00319.pdf  
I wanted to receive the attachment with original file name.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [September 24, 2008, 10:30am UTC](https://www.ruby-forum.com/t/pdf-attachment-to-be-in-the-same-name/147396/2 "2008-09-24T10:30:29Z")

</div>

Vidya, the fix for this issue is you need to put r+b when creating the  
file.

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
```
