如何使用 ActionMailer 防止电子邮件附件内联呈现
我使用以下代码发送带有 pdf 附件的电子邮件:
class StudyMailer < ActionMailer::Base
def notify_office(study, sent_at = Time.now)
subject "Email Subject Goes Here"
recipients '[email protected]'
from "#{study.sender.full_name} <#{study.sender.email}>"
sent_on sent_at
body :study => study
for document in study.documents
attachment :content_type => "application/pdf", :body => File.read(document.document.path) #absolute path to .pdf document
end
end
end
发送电子邮件时,附件似乎内联呈现为二进制代码而不是 .pdf 附件。
如何将 .pdf 呈现为典型附件,而不是内联附件?
I am using the following code to send an email with a pdf attachment:
class StudyMailer < ActionMailer::Base
def notify_office(study, sent_at = Time.now)
subject "Email Subject Goes Here"
recipients '[email protected]'
from "#{study.sender.full_name} <#{study.sender.email}>"
sent_on sent_at
body :study => study
for document in study.documents
attachment :content_type => "application/pdf", :body => File.read(document.document.path) #absolute path to .pdf document
end
end
end
When the email is sent, the attachment seems to render inline as binary code rather than as a .pdf attachment.
How do I render the .pdf as a typical attachment, rather than inline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意内容处置线。
Notice the content-disposition line.
我相信您必须指明电子邮件的多部分性质,因此请在
from
行下添加此行:I believe you have to indicate the multipart nature of the email, so add this line under the
from
line:您的电子邮件有模板吗?如果电子邮件没有模板,即使其他所有设置均正确,附件也会内联显示。创建附件电子邮件模板。
然后在通知程序中指定使用此模板。
Does your email have a template? If the email does not have a template, the attachment shows up inline even if everything else is set up correctly. Create an attachment email template.
Then in Notifier, specify to use this template.