Question

Here is my mailer:

class MailIt < ActionMailer::Base

    def funny(sender)
        @sender = sender
        attachments['funny.pdf'] = File.read("#{Rails.root}/app/assets/funny.pdf")
        mail(:to => "amail@example.com",
             :from => "amail@example.com",
             :subject => "TESST")
    end

end

I get the e-mail with the attached pdf but it is damaged and the file size is only 1/4 of the original file.

No correct solution

OTHER TIPS

if you have images in your pdf, you have to send it as binary.

attachments['funny.pdf'] = File.read("#{Rails.root}/app/assets/funny.pdf", :mode => 'rb')

I did find a solution.

It seems like there is a problem with File.read

I tried this and it worked:

attachments['funny.pdf'] = File.open("#{Rails.root}/app/assets/funny.pdf").read
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top