比默认参数为轨道访问更多(到,发件人,主题,REPLY_TO)邮件拦截
问题描述:
我有一个邮件中的一个方法叫做notification_mailer.rb
:比默认参数为轨道访问更多(到,发件人,主题,REPLY_TO)邮件拦截
def reminder_email
@community = @reminder.community
subject = "random subject text"
mail(from: address_for(support), reply_to: address_for(support), to: to_address, subject: subject)
end
我试图使用邮件拦截check_mail_settings.rb
:
class CheckMailSettings
def self.delivering_email(mail)
if @community.status = "mute"
mail.perform_deliveries = false
end
end
end
ActionMailer::Base.register_interceptor(CheckMailSettings)
但是这个拦截器实际上并没有访问@community
变量。我试图通过它在邮件呼叫notification_mailer.rb
像这样
mail(community: @community, from: address_for(support).....)
和拦截check_mail_settings.rb
内访问它像这样
mail.community
但这并不工作。
有什么办法可以拦截check_mail_settings.rb
内访问该@community
变量或者我需要做涉及notification_mailer.rb
事先内@community
任何条件语句?
答
虽然我不认为你在做什么,真的是有道理的,这是可能的。
在拦截你得到的Mail::Message
一个实例。它可以访问任何你通过mail
的电话。
所以这个例子,你提供的那种
mail[:community].value