繁体   English   中英

通过邮件发送attchemnt的Rails Mailer问题

[英]Rails Mailer issue with sending attchemnt over mail

我正在将应用程序从Rails 2.3迁移到Rails 3.1,当我发送带有附件的电子邮件时,电子邮件无法正常工作,我在电子邮件中看到了带有编码的pdf内容而不是附件的纯文本/文本电子邮件。

这是我用来发送电子邮件的命令

ret = UserMailer.return_forms(@customer[:email], @store, id, @customer[:document]).deliver

这是return_form的定义,return_forms是UserMailer类中的方法(class UserMailer < ActionMailer::Base)

  def return_forms(email, store, order, pdf_document_path)
    load_smtp_settings("noreply")
    @recipients = email
    @subject    = "#{business_name}: Return forms"
    @body       = "Please follow the instructions within the forms to return your merchandise. Thank You."
    attachments['free_book.pdf'] = {mime_type: 'application/pdf',content:  File.read(pdf_document_path) }
    @from       = email
    @date    = Time.zone.now
    @headers    = {}
  end

我认为内容是

--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <55c881028af96_48d43fe94782e9a0658aa@amol-desktop.mail>

Please follow the instructions within the forms to return your merchandise. Thank You.

--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: application/pdf;
 charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename=free_book.pdf
Content-ID: <55c88102872ba_48d43fe94782e9a0657a0@amol-desktop.mail>

JVBERi0xLjQKJcfsj6IKNyAwIG9iago8PC9MZW5ndGggOCAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nH1W227bOBB991cM0AWqABZLUvc8
bTZNivTiuLUX2GKzD6xE22pk0aWktOnX75CSbUW+xEhkDufMGc4cjvIDKGFA
zad7puvRmy8JLKuRtYJejnyfghd5MQRBSIGjTY4W1srDkB+xeh4HHocQ92yM
clxzr7NFLD6w7fx6WOtn4gWhD2ewjEfeaZIeuHW0GUYxg3Nwn/rhGaI+vnVt
8wzhHN4PqX+GqQ+3njbTxIez8DhOzhD14dZzUM+j8MD3zxH14K3nIOZReEjp

return_forms调用的结尾应该有一个mail()方法的调用。 就像是:

mail(:from => your_from, :to => your_to, :subject => your_subject, :body => your_body)

在development.rb中启用邮件错误以查看是否出现任何错误也是一个好主意:

config.action_mailer.raise_delivery_errors = true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM