Ruby on rails 如何防止使用ActionMailer内联呈现电子邮件附件
我使用以下代码发送带有pdf附件的电子邮件:Ruby on rails 如何防止使用ActionMailer内联呈现电子邮件附件,ruby-on-rails,actionmailer,email-attachments,Ruby On Rails,Actionmailer,Email Attachments,我使用以下代码发送带有pdf附件的电子邮件: class StudyMailer < ActionMailer::Base def notify_office(study, sent_at = Time.now) subject "Email Subject Goes Here" recipients 'user@domain.come' from "#{study.sender.full_name} <#{study.sender.em
class StudyMailer < ActionMailer::Base
def notify_office(study, sent_at = Time.now)
subject "Email Subject Goes Here"
recipients 'user@domain.come'
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
class StudyMailer研究
用于研究中的文档。文档
附件:content_type=>“application/pdf”,:body=>File.read(document.document.path)#到.pdf文档的绝对路径
结束
结束
结束
发送电子邮件时,附件似乎以二进制代码的形式内联呈现,而不是以.pdf附件的形式呈现
如何将.pdf呈现为典型的附件而不是内联附件
attachment :content_type => "application/pdf",
:content_disposition => "attachment",
:filename => File.basename(fattach),
:body => File.new(fattach,'rb').read()
请注意内容处置行
请注意内容处置行。我认为您必须指出电子邮件的多部分性质,因此请将此行添加到
from
行下:
content_type "multipart/alternative"
我相信您必须指出电子邮件的多部分性质,因此在
发件人
行下添加这一行:
content_type "multipart/alternative"
你的电子邮件有模板吗?如果电子邮件没有模板,则即使其他内容设置正确,附件也会以内联方式显示。创建附件电子邮件模板 views/notifier/attachment.html.erb
你的电子邮件有模板吗?如果电子邮件没有模板,则即使其他内容设置正确,附件也会以内联方式显示。创建附件电子邮件模板 views/notifier/attachment.html.erb
添加内容类型似乎不会影响附件的呈现方式。添加内容类型似乎不会影响附件的呈现方式。在块中添加附件似乎不会影响附件的呈现方式。结果表明,此问题与电子邮件视图模板的名称有关,而与其他任何问题无关,但我将此标记为答案,因为还需要内容处理块。在块中添加附件似乎不会影响附件的呈现方式。结果表明,此问题与电子邮件视图模板的名称有关,而不是其他任何问题,但我把这个标记为答案,因为还需要内容处理块。
def my_email_method
...
mail(:template_name => 'attachment', :from => from_address, ...)
end