【问题标题】:PDF attachment in email is called 'Noname'电子邮件中的 PDF 附件称为“Noname”
【发布时间】:2018-06-29 16:30:46
【问题描述】:

当我发送附有 pdf 文件的电子邮件时,电子邮件仅显示名为“Noname”的文件。该文件本身是电子邮件的多部分部分,带有 base64 附件 pdf。如何发送 PDF 以使其作为附件出现并且不会损坏电子邮件?

这是我的代码:

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

【问题讨论】:

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


    【解决方案1】:

    我也遇到过同样的问题。我已经通过以下方式更正了它

    1) 根据 ActionMailer 指南,您需要将视图文件放入 app/views/[action_mailer_model_name]/[method_name]

    这里是指南参考:http://api.rubyonrails.org/classes/ActionMailer/Base.html

    2) Action Mailer 足够智能,可以在读取文件时自动识别内容类型。因此,无需在您的邮件功能中明确传递“应用程序/pdf”。

    希望这些信息有助于解决您的问题

    【讨论】:

      【解决方案2】:

      也遇到了同样的问题 解决方案是: 发送邮件功能前设置附件。

      代码附在下面:

       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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-22
        • 1970-01-01
        • 2015-05-02
        • 2023-03-07
        • 2021-06-26
        • 1970-01-01
        • 2011-10-09
        相关资源
        最近更新 更多