【问题标题】:Attachment not sent properly in rails using ActionMailer使用 ActionMailer 在 Rails 中未正确发送附件
【发布时间】:2014-06-04 18:17:58
【问题描述】:

我正在尝试通过 ActionMailer 发送 xls 文件。

mailer = ActionMailer::Base.mail(:to => "reciever@gmail.com", :from => "sender@gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments['filename.xls']= {mime_type: 'application/vnd.ms-excel', content: File.read("filePath.xls")}
mailer.deliver!

我也能收到邮件。 但不知何故,附件不正确,它显示为 noname,下面是我在文件中得到的内容(我正在复制粘贴确切的内容)

--

Date: Wed, 04 Jun 2014 23:33:48 +0530
Mime-Version: 1.0
Content-Type: application/vnd.ms-excel;
 charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename=filename.xls
Content-ID: <538f5f82836992@C02L2178FFT3.gmail>

PGgzIHN0eWxlPSJmb250LXdlaWdodDpib2xkIj4gCiAgICBTaG93aW5nCiAg
ICBvcGVuCiAgICByZXF1ZXN0cwogICAgZnJvbQogICAgTm92IDIxLCAyMDEz
....

我确定我错过了一些简单的东西,我无法弄清楚是什么。有人可以帮忙吗?

【问题讨论】:

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


【解决方案1】:

试试这个:--

mailer = ActionMailer::Base.mail(:to => "reciever@gmail.com", :from => "sender@gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments["filename.xls"]= File.read("filePath.xls")
mailer.deliver!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2016-10-11
    • 2012-12-26
    相关资源
    最近更新 更多