Rails - ActionMailer有时会在电子邮件内容之前显示附件?

AnA*_*ice 5 ruby-on-rails actionmailer ruby-on-rails-3

我怎么能这样做,所以ActionMailer总是在消息的底部显示附件:HTML,TXT,附件....

问题是这里的附件是一个文本文件:

----==_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: <4d8f976d49c72_4f0d15a519e351387611f@railgun64.53331.mail>
Run Code Online (Sandbox Code Playgroud)

谢谢

Jac*_*ler 5

我知道已经有一个已接受的答案,但改变顺序attachments[]并且mail()没有为我解决.我的情况有什么不同,我试图附加一个文本文件附件(.txt)

对我有用的是为邮件设置content_typeparts_order默认值.

MyMailer < ActionMailer::Base

    default :from => "Awesome App <support@example.com>",
            :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
Run Code Online (Sandbox Code Playgroud)

如果您要发送一封电子邮件在Rails 3中使用纯文本文件(.txt),试图将:content_typeparts_order你的默认设置,从而文本文件不会出现在你的电子邮件上述消息.


Kar*_*lis 4

我遇到了同样的问题,就我而言,解决方案是交换附件和邮件线路。先附加,再调用邮件。

轨道3

错误的

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

好的

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