2011-03-27 42 views
5

我怎樣才能使這樣的ActionMailer始終顯示在郵件的底部附件: HTML,TXT,附件....Rails - ActionMailer有時會在電子郵件內容前顯示附件?

問題是這裏的附件是一個文本文件:

----==_mimepart_4d8f976d6359a_4f0d15a519e35138763f4 
Date: Sun, 27 Mar 2011 13:00:45 -0700 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; 
filename=x00_129999.olk14message 
Content-ID: <[email protected]> 

由於

+0

你可以發佈郵件內的代碼嗎?我懷疑我知道問題可能是什麼。 – Tass 2011-04-20 22:01:22

+0

@AnApprentice我有同樣的問題。你能解決嗎? – Wukerplank 2011-07-14 09:10:29

回答

4

我有同樣的問題,在我的情況下,解決方案是交換附件和郵件行。首先附上,然後致電郵件。

的Rails 3

WRONG

def pdf_email(email, subject, pdfname, pdfpath) 
    mail(:to => email, :subject => subject) 
    attachments[pdfname] = File.read(pdfpath) 
end 

GOOD

def pdf_email(email, subject, pdfname, pdfpath) 
    attachments[pdfname] = File.read(pdfpath) 
    mail(:to => email, :subject => subject) 
end 
+0

nope。沒有解決「訂購」問題 – choonkeat 2013-10-08 06:28:45

0

這是鐵路2.3代碼(可能是在Rails3中略有不同)

附件之前只是移動你的文字部分

recipients [email protected] 
from  [email protected] 
subject "some subject" 
content_type "multipart/mixed" 

part "text/plain" do |p| 
    p.body = render_message 'my_message' #this is template file 
end 

attachment "application/octet-stream" do |a| 
    a.body = File.read("some_file.jpg") 
    a.filename = 'name.jpg' 
end 
5

我知道已經有一個公認的答案,但切換的attachments[]順序和mail()沒有爲我解決它。我的情況有所不同的是,我試圖添加文本文件附件(.txt)

對我而言,適用於郵件程序的默認設置爲content_typeparts_order

MyMailer < ActionMailer::Base 

    default :from => "Awesome App <[email protected]>", 
      :content_type => 'multipart/alternative', 
      :parts_order => [ "text/html", "text/enriched", "text/plain", "application/pdf" ] 

    def pdf_email(email, subject, pdfname, pdfpath) 
     attachments[pdfname] = File.read(pdfpath) 
     mail(:to => email, :subject => subject) 
    end 

    def txt_email(email, subject, filename, filebody) 
     attachments[filename] = filebody 
     mail(:to => email, :subject => subject) 
    end 
end 

如果您要發送一封電子郵件中Rails 3中使用純文本文件(.txt),試圖將:content_typeparts_order你的默認設置,從而文本文件不會出現在您的電子郵件消息上方。

+1

'parts_order'工作。儘管不一定會放入「默認」部分。它可以作爲單個「郵件(...)」的參數 – choonkeat 2013-10-08 06:27:32

相關問題