【问题标题】:Rails or my SMTP client Gmail, does not allow large CSV file attachmentsRails 或我的 SMTP 客户端 Gmail,不允许使用大型 CSV 文件附件
【发布时间】:2014-07-29 19:17:31
【问题描述】:

我正在尝试让 ActionMailer 交付我生成的 CSV:

@csv= CSV.generate(force_quotes: true) do |csv|
  ::CourseExportGenerator.load_template csv, sections, standard, registration
end   

@filename = "my_sweet_filename.csv"
EnterpriseMailer.send_report(@csv, @filename).deliver

然后我的 EnterpriseMailer.rb 文件看起来像这样:

def send_report report, filename
  attachments["#{filename}"] = {data: report, encoding: 'base64'}
  mail to: 'trip@triptrip.com', subject: "Your large CSV file!"
end

电子邮件的主题正确,但没有我的实际内容(只是一些简单的占位符文本)。附加的文件标题为“noname”,打开时显示为:

This is a multi-part message in MIME format...

----

我知道它传送的文件大约有 2 到 3 兆字节,并且有超过 8,000 行。

有谁知道我如何发送电子邮件附件中的大型 CSV 文件?也许我写的语法不正确?

【问题讨论】:

    标签: ruby-on-rails csv gmail mime-types actionmailer


    【解决方案1】:

    答案是我必须在邮件程序本身创建这个文件。不知道为什么会这样,但确实如此。

    我的 enterprise_mailer.rb 看起来像这样:

    attachments["#{@filename}"] = CSV.generate(force_quotes: true) do |csv|
      ::ExportGenerator.load_template csv, sections, standard, registration
    end
    mail to: 'trip@triptrip.com', subject: "My totally awesome subject line"
    

    【讨论】:

      猜你喜欢
      • 2011-07-03
      • 2015-05-18
      • 2019-09-02
      • 2021-08-30
      • 1970-01-01
      • 2015-10-23
      • 2019-08-18
      • 1970-01-01
      相关资源
      最近更新 更多