# Attaching files to emails using ActionMailer

**URL:** <https://www.ruby-forum.com/t/attaching-files-to-emails-using-actionmailer/168465>\
**Category:** Rails\
**Created:** [May 21, 2009, 2:48am UTC](https://www.ruby-forum.com/t/attaching-files-to-emails-using-actionmailer/168465 "2009-05-21T02:48:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stewart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@Stewart](https://www.ruby-forum.com/u/Stewart)\
**Post date:** [May 21, 2009, 2:48am UTC](https://www.ruby-forum.com/t/attaching-files-to-emails-using-actionmailer/168465/1 "2009-05-21T02:48:22Z")

</div>

Hey Guys,

I wish to generate a PDF on the fly to attach to an email. I am using  
action mailer and I want to tell the action mailer to attach a PDF  
from a URL not a file. All of the examples I have seen attach the  
file to the email like so…

```
  attachment :content_type => "image/jpeg",
    :body => File.read("an-image.jpg")

```

Is there anyway I can make it so that “an-image.jpg” is called from a  
url on the localhost so something like “localhost/invoice.pdf”. This  
will fit in to my rails app as it generates a PDF using prawn and  
prawnto from that url.

Thanks for any help

---

<div class="post-metadata">

**Author:** ![Stewart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@Stewart](https://www.ruby-forum.com/u/Stewart)\
**Post date:** [May 21, 2009, 3:02am UTC](https://www.ruby-forum.com/t/attaching-files-to-emails-using-actionmailer/168465/2 "2009-05-21T03:02:24Z")

</div>

didn’t try this myself, but use open-uri?

```
  attachment :content_type => "image/jpeg",
    :body => open("http://site.com/an-image.jpg").read
```
