Rails beginner
Rails beginner

Reputation: 14504

Rails mailer PDF attachment broken

In one of my mailers I have this method to send an e-mail with an attached pdf:

def send_offer(customer, ip)
    @customer = customer
    attachments['offer.pdf'] = {
      :encoding => 'base64',
      :content  => Base64.encode64(File.read(Rails.root.join('app', 'assets', 'images', 'offer.pdf')))
    }
    mail(:to => "[email protected]",
         :from => "[email protected]",
         :body =>"this tag is important when do any attachment",
         :subject => "#{@customer[:name]} Offer")
end

The e-mails is send, but when I open it the attached PDF is broken. The file size is 670 bytes.

The original PDF is 263 KB (269.485 byte)

How can that be?

Upvotes: 1

Views: 1201

Answers (1)

Ilya
Ilya

Reputation: 121

I had the same problem and solution from here helped me to solve it:

attachments[file_name] = File.open(file_location, 'rb'){|f| f.read}

Upvotes: 2

Related Questions