# ActionMailer attaching generated files

**URL:** <https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634>\
**Category:** Rails\
**Created:** [January 31, 2010, 6:22pm UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634 "2010-01-31T18:22:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [January 31, 2010, 6:22pm UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634/1 "2010-01-31T18:22:44Z")

</div>

I have a script that is running as a runner script, its job is to find  
reports that have recently been published and send emails to the users  
notifying them of the reports. The reports are available online, but  
are also available via a generated PDF which the users can see by  
tacking on .pdf to the end of their URL.

I want to attach the pdf to the email that the runner script sends  
out. The problem I’m facing is that the runner script cannot ‘find’  
the pdf and I dont know why - here are my guesses:

1. You have to authenticate to see the pdf reports (which is true, but  
im not sure if the action mailer needs to authenticate and cannot do  
that?)

2. I am only able to use the path of the pdf, not the full url. The  
pdf is available through a url obviously, but the url contains a  
subdomain - but because this is a runner script that runs behind the  
scenes, it has no context and therefor cannot determine the URL.

I’m not sure which one is causing the failure, anyone have any ideas?

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [February 1, 2010, 9:29am UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634/2 "2010-02-01T09:29:18Z")

</div>

On Jan 31, 4:48 pm, Ryan A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. You have to authenticate to see the pdf reports (which is true, but  
> im not sure if the action mailer needs to authenticate and cannot do  
> that?)
> 
> 2. I am only able to use the path of the pdf, not the full url. The  
> pdf is available through a url obviously, but the url contains a  
> subdomain - but because this is a runner script that runs behind the  
> scenes, it has no context and therefor cannot determine the URL.

Are you trying to attach the pdf by giving actionmailer the path from  
the url that generates the pdf (ie /some\_controller/some\_id/  
generate.pdf or similar) ? That sounds very roundabout, and just out  
of the box you need to give actionmailer a path to an actual file on  
disk. You’d be far better off invoking the actual pdf generation code  
from your script.

Fred

Fred

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [February 10, 2010, 6:32am UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634/3 "2010-02-10T06:32:53Z")

</div>

Yes I am attempting to basically give it a URL, I’m not sure how else  
to do it…

On Feb 1, 3:27 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [February 10, 2010, 9:13am UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634/4 "2010-02-10T09:13:50Z")

</div>

On Feb 10, 5:30 am, Ryan A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes I am attempting to basically give it a URL, I’m not sure how else  
> to do it…

Well you’ve got code to generate a pdf document, use that to save it  
as a temporary file and attach that temporary file to the email.

Fred

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [February 10, 2010, 6:37am UTC](https://www.ruby-forum.com/t/actionmailer-attaching-generated-files/182634/5 "2010-02-10T06:37:23Z")

</div>

Ryan A. wrote:

> Yes I am attempting to basically give it a URL, I’m not sure how else  
> to do it…
> 
> On Feb 1, 3:27ï¿½am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Why are you mailing the PDF files anyway? The URL should be sufficient.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
