rake任务中的Rails ActionMailer附件无法按预期工作

时间:2013-07-01 20:34:57

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

在rake测试中,我以这种方式调用ActionMailer :: Base:

namespace :mine do
  desc "it sends emails"
  mailer = ActionMailer::Base.mail(:from => 'whoever', :to => 'whoemever', :subject => "hi        there") do |format|
    format.text do
      render :text => 'my list'
    end
  end
  mailer.attachments['myfile.csv'] = { :content => File.read('/tmp/file.csv'),
                                             :mime_type => 'text/csv'
                                           }
  mailer.deliver
end

邮件被发送,但附件被放入电子邮件正文中..看起来像这样:

— Date: Mon, 01 Jul 2013 16:26:25 -0400 Mime-Version: 1.0 Content-Type: text/csv;

charset=UTF-8
Content-Transfer-Encoding: 7bit Content-Disposition: attachment;

filename=my_file.csv

然后转储文件。关于为什么会发生这种情况的任何想法?

0 个答案:

没有答案