[Rails 3.2.13] .text.erb
과 .html.haml
템플릿을 기반으로하는 암시 적 multipart 이메일을 보내는 메일러가 있습니다. 거기에 문제 없습니다.ActionMailer after_filter breaking content_type
잘못된 이메일 전송을 조건부로 방지하기 위해 after_filter를 추가하려고합니다. this answer 및 내가 읽은 모든 문서를 기반으로하면 매우 간단합니다.
그러나이 after_filter을 포함하는 multipart/alternative
에서 text/plain
콘텐츠 유형을 변경 이메일이 유효한 경우에도 마찬가지입니다. 문서에서 : '첨부 파일이나 부품이 전자 메일에 추가 된 경우 암시 적 템플릿 렌더링이 수행되지 않습니다.' 그게 여기에 적용됩니까? 이 예상 된 동작입니까, 아니면 내가 잘못하고 있습니까?
내 머리를 벽에 부딪히는 것은 매우 단순 해 보입니다.
class Notify < ActionMailer::Base
include AbstractController::Callbacks
after_filter :ensure_valid
def some_email(user_id)
@user = User.find(user_id)
mail(to: @user.email)
end
...
private
def ensure_valid
if User.where(email: mail.to, invalid_email: true).any?
mail.perform_deliveries = false
end
true
end
end
편집 :
def ensure_valid
puts "mail: #{mail}"
true
end
여기 무슨 일이야 : 더 땜질 후, 심지어 같은과 함께 after_filter의 모든이 여러 부분을 해제에 mail
객체 를 호출하는 것 같다?
시도 after_filter 다시 수동 CONTENT_TYPE + PARAMS 첨가, 예를 들어
mail.content_type = 'multipart/alternative'
mail.header['Content-Type'].parameters[:boundary] = mail.body.boundary
mail.header['Content-Type'].parameters[:charset] = 'UTF-8'
하지만 어떤 이유로이 기능이 작동하지 않는 것 같습니다.
mail.content_type = 'multipart/alternative'
.. 만 포함하면 content_type이 설정되지만 경계 및 charset 매개 변수가 누락됩니다.
- 설정 기본 콘텐츠 _을으로 environment.rb에
- 설정 기본 콘텐츠 _를 메일러