Rails - ActionMailer有时会在电子邮件内容前显示附件?
我怎样才能使这样的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]>
由于
我有同样的问题,在我的情况下,解决方案是交换附件和邮件行。首先附上,然后致电邮件。
的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
nope。没有解决“订购”问题 – choonkeat 2013-10-08 06:28:45
这是铁路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
我知道已经有一个公认的答案,但切换的attachments[]
顺序和mail()
没有为我解决它。我的情况有所不同的是,我试图添加文本文件附件(.txt)
对我而言,适用于邮件程序的默认设置为content_type
和parts_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_type
和parts_order
你的默认设置,从而文本文件不会出现在您的电子邮件消息上方。
'parts_order'工作。尽管不一定会放入“默认”部分。它可以作为单个“邮件(...)”的参数 – choonkeat 2013-10-08 06:27:32
你可以发布邮件内的代码吗?我怀疑我知道问题可能是什么。 – Tass 2011-04-20 22:01:22
@AnApprentice我有同样的问题。你能解决吗? – Wukerplank 2011-07-14 09:10:29