Rails邮件程序PDF附件坏了

时间:2013-04-03 10:27:52

标签: ruby-on-rails ruby ruby-on-rails-3

在我的一封邮件中,我有这种方法发送附带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 => "mail@example.com",
         :from => "mail@example.com",
         :body =>"this tag is important when do any attachment",
         :subject => "#{@customer[:name]} Offer")
end

发送电子邮件,但是当我打开它时,附加的PDF文件被破坏了。文件大小为670 bytes

原始PDF为263 KB (269.485 byte)

怎么会这样?

1 个答案:

答案 0 :(得分:1)

我有同样的问题,here的解决方案帮我解决了问题:

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