# Sending Documents via ActionMailer

**URL:** <https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561>\
**Category:** Rails\
**Created:** [March 8, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561 "2006-03-08T17:14:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xcandyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@xcandyman](https://www.ruby-forum.com/u/xcandyman)\
**Post date:** [March 8, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561/1 "2006-03-08T17:14:03Z")

</div>

Hi,

I’ve been trying to set up to send already generated PDF’s via the  
ActionMailer class however it dosn’t seem to send the full file. So when  
I try to load the file after being sent it via email it dosn’t because  
it is corrupt. When I choose to send HTML instead it sends fine but it  
dosn’t work with Word Documents either

Do I need to do anything special for other file types?

Thanks

---

<div class="post-metadata">

**Author:** ![xcandyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@xcandyman](https://www.ruby-forum.com/u/xcandyman)\
**Post date:** [March 9, 2006, 9:53am UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561/2 "2006-03-09T09:53:58Z")

</div>

Bump?

---

<div class="post-metadata">

**Author:** ![xcandyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@xcandyman](https://www.ruby-forum.com/u/xcandyman)\
**Post date:** [March 11, 2006, 7:44pm UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561/3 "2006-03-11T19:44:44Z")

</div>

no-one? I’ve tried everything it seems and dosnt seem to be doing  
anything

---

<div class="post-metadata">

**Author:** ![xcandyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@xcandyman](https://www.ruby-forum.com/u/xcandyman)\
**Post date:** [March 12, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561/4 "2006-03-12T23:20:35Z")

</div>

Ste H. wrote:

> no-one? I’ve tried everything it seems and dosnt seem to be doing  
> anything

Sadly, this seems to be another one of those poorly-documented Rails  
scenarios.

I managed to send a PDF attachment with a text E-mail message for a  
project that has since been put on hold (so I haven’t run the code in  
two months, and don’t recall just how well it worked).

This is a method from my ActionMailer-derived class

def pdf\_invoice mail\_params, pdf  
recipients mail\_params[:to]  
cc mail\_params[:cc]  
from mail\_params[:user\_email]  
subject mail\_params[:subject]

```
 part :content_type => "text/plain",
      :body => render_message( 'pdf_invoice.text.plain',
                                :note => mail_params[:note] )

 attachment :content_type => "application/pdf",
    :filename => mail_params[:base_filename].to_s + '.pdf',
    :body => pdf

```

end

–  
James B.

Judge a man by his questions, rather than his answers.

- Voltaire

---

<div class="post-metadata">

**Author:** ![xcandyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@xcandyman](https://www.ruby-forum.com/u/xcandyman)\
**Post date:** [March 13, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/sending-documents-via-actionmailer/54561/5 "2006-03-13T15:05:20Z")

</div>

Hi James thanks for the email, unfortunatly its not suitable for what I  
need. For each item in my database has a PDF file already created and I  
want to be able to automatically send the PDF attachment by a single  
click.

Thanks

James B. wrote:

> Ste H. wrote:
> 
> > no-one? I’ve tried everything it seems and dosnt seem to be doing  
> > anything
> 
> Sadly, this seems to be another one of those poorly-documented Rails  
> scenarios.
> 
> I managed to send a PDF attachment with a text E-mail message for a  
> project that has since been put on hold (so I haven’t run the code in  
> two months, and don’t recall just how well it worked).
> 
> This is a method from my ActionMailer-derived class
> 
> def pdf\_invoice mail\_params, pdf  
> recipients mail\_params[:to]  
> cc mail\_params[:cc]  
> from mail\_params[:user\_email]  
> subject mail\_params[:subject]
> 
> ```
> part :content_type => "text/plain",
> :body => render_message( 'pdf_invoice.text.plain',
> :note => mail_params[:note] )
> 
> attachment :content_type => "application/pdf",
> :filename => mail_params[:base_filename].to_s + '.pdf',
> :body => pdf
> 
> ```
> 
> end
> 
> –  
> James B.
> 
> Judge a man by his questions, rather than his answers.
> 
> - Voltaire
