RoR ActionMailer发送内联附件而不是常规附件

时间:2014-08-22 08:59:29

标签: ruby-on-rails actionmailer

我尝试通过邮件发送NOT INLINE附件:

m = ActionMailer::Base.mail(:to => "ex@ex.pl", :from => "ex1@ex.pl", :subject=>"test")
m.attachments["test.csv"] = File.read("#{Rails.root}/lib/tasks/test.csv")
m.deliver

当收件人收到邮件时,附件显示为INLINE(邮件正文中包含附件文本)。

Rails 3.2.19 Ruby 2.1.2p95

请给我建议,如何修理并发送附件邮件附件等附件;)

2 个答案:

答案 0 :(得分:2)

这项工作对我来说:

class ReportMailer < ActionMailer::Base
    def send_report
        attachments["test.csv"] = {mime_type: 'text/csv', content: File.read(Rails.root.join('lib', 'tasks', 'test.csv'))}
        mail(:to => "", :from => "", :subject=>"") do |format|
                format.text {render :text => ""}
        end
    end
end

ReportMailer.send_report.deliver

答案 1 :(得分:0)

尝试指定mime类型和内容处理:

m.attachments["test.csv"] = {mime_type: 'text/csv',                            
                             content: File.read("#{Rails.root}/lib/tasks/test.csv"),
                             content_disposition: 'attachment'}