Rails 3.0.17发送内联附件而不是常规附件

时间:2012-12-19 10:36:24

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

所以,我们刚刚在Ruby 1.8.7企业版的基础上将我们的项目升级到Rails 3.0.17(请不要问为什么这个特定的版本,只是这样)。

我有生成CSV数据并通过电子邮件将其作为文件发送的方法。

# contact_mailer.rb
def send_payments_report
  attachments["report.csv"] = {
    :content => Payment.generate_csv_report,
    :mime_type => "text/csv"
  }

  mail(
    :from => "from@example.com",
    :subject => "Payments report",
    :to => "to@example.com"
  )   
end

以下是它的回报:

=> #<Mail::Message:2231891440, Multipart: true, Headers: <Date: Wed, 19 Dec 2012 11:48:05 +0200>, <From: from@example.com>, <To: to@example.com>, <Message-ID: <50d18d555dcdc_2269838ab93812784@artem.local.mail>>, <Subject: Payments report>, <Mime-Version: 1.0>, <Content-Type: multipart/mixed; >, <Content-Transfer-Encoding: 7bit>>

电子邮件本身显示为没有附件的纯文本:

--
Date: Wed, 19 Dec 2012 11:48:05 +0200
Mime-Version: 1.0
Content-Type: text/csv;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=report.csv
Content-ID: <50d18d555dcdc_2269838ab93812784@artem.local.mail>

"customer id","reference nr","invoice id","invoice type","invoice sum","sum paid","payment date"
"1035","010294","7113","Fine","250.00","100.00","2012-11-15"
"1035","010294","6132","Fine","250.00","250.00","2012-11-15"
"1035","010294","5241","Fine","850.00","650.00","2012-11-15"
--

我尝试附加现有文件,但它以相同的方式显示它。它在Rails 2.3.9上完美运行。任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:0)

我似乎已经解决了这个问题。 这是我如何调用mail方法:

mail(
  :from => "from@example.com",
  :subject => "Payments report",
  :to => "to@example.com"
) do |format|
    format.text {render :text => ""}
end