簡體   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