Sending Documents via ActionMailer


#1

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


#2

Bump?


#3

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


#4

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

#5

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