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

2023-12-10

我怎样才能让 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: <[email protected]>

Thanks


我知道已经有一个被接受的答案,但是交换顺序attachments[] and mail()没有为我解决。我的情况的不同之处在于我试图附加文本文件附件(.txt)

对我有用的是设置content_type and 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 and parts_order更改为默认值,以便文本文件不会出现在电子邮件中的消息上方。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails - ActionMailer 有时会在电子邮件内容之前显示附件? 的相关文章

随机推荐