ActionMailer를 사용하여 이메일 첨부 파일을 인라인으로 렌더링하는 것을 방지하려면 어떻게합니까?
-
19-09-2019 - |
문제
다음 코드를 사용하여 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.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를 인라인보다는 일반적인 부착물로 어떻게 렌더링합니까?
해결책
attachment :content_type => "application/pdf",
:content_disposition => "attachment",
:filename => File.basename(fattach),
:body => File.new(fattach,'rb').read()
내용화 선을 주목하십시오.
다른 팁
이메일의 다중 특성을 표시해야한다고 생각 하므로이 줄을 추가하십시오. from
선:
content_type "multipart/alternative"
이메일에 템플릿이 있습니까? 이메일에 템플릿이없는 경우 다른 모든 것이 올바르게 설정되어 있어도 첨부 파일이 인라인으로 나타납니다. 첨부 이메일 템플릿을 만듭니다.
views/notifier/attachment.html.erb
<p> Please see attachment </p>
그런 다음 Notifier 에서이 템플릿을 사용하도록 지정하십시오.
Notifier.rb
def my_email_method
...
mail(:template_name => 'attachment', :from => from_address, ...)
end
제휴하지 않습니다 StackOverflow