3

When I send an email with a attached pdf file the email only shows a file called 'Noname'. The file itself is the multipart section of the email with the base64 attached pdf. How can I send the PDF so it comes up as an attachment and doesn't corrupt the email?

Here is my code:

attachments['126539_statistics.pdf'] = File.read("app/assets/pdfs/126539_statistics.pdf")
mail(:to => email, :subject => subject, :body => message,  :content_type => 'application/pdf') 

2 Answers 2

8

I had face same problem. I have corrected it by following way

1) As per ActionMailer Guide, You need to make view file into app/views/[action_mailer_model_name]/[method_name]

Here is reference of guide: http://api.rubyonrails.org/classes/ActionMailer/Base.html

2) Action Mailer is smart enough that it identify content-type automatically while reading file. So there is no need to pass explicitly 'application/pdf' in your mail function.

Hope, this information helps to solve your problem

0
4

Also experienced the same problem solution is : set Attachments before sending mail function.

code is attached below:

 attachments["invoice_#{invoice.bill_date.strftime('%B-%Y')}.pdf"] = WickedPdf.new.pdf_from_string(
        render_to_string  pdf: 'project_report.pdf',
                          template: 'users/_invoice.html.erb'
    )
    mail(to: email , from: from, subject: subject) do |format|
          format.html
      end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.