0

任何人都可以向我解释我在哪里可以找到关于什么是属性delivery_handler的具体解释?什么样的对象?一个字符串?管他呢 ?

以及该指令的工作原理:

filteredMailers.include?(message.delivery_handler)

我从这个邮件观察者上下文中得到它:

class DevelopmentMailInterceptor
  def self.delivering_email(message)

    filteredMailers = %w[
      NotificationMailer
    ]

    if filteredMailers.include?(message.delivery_handler)
      message.subject = "[filter] To:#{message.to} - #{message.subjec}"
      message.to = 'logs@mail.com'
    end

    return message
  end
end

我找到了消息类的this reference,但是对于delivery_handler是什么类型的对象仍然很困惑。

欢迎任何帮助。感谢您的解释。

4

1 回答 1

0

它记录在https://github.com/mikel/mail/blob/2.6.1/lib/mail/message.rb#L138

您应该为其分配一个类,该类实现deliver_mail可以/应该执行以下任何操作的方法(引用自上面的链接):

# * Appending the mail object to Mail.deliveries as you see fit.
# * Checking the mail.perform_deliveries flag to decide if you should
#   actually call :deliver! the mail object or not.
# * Checking the mail.raise_delivery_errors flag to decide if you
#   should raise delivery errors if they occur.
# * Actually calling :deliver! (with the bang) on the mail object to
#   get it to deliver itself.

除了 call deliver!,您还可以 call yield,这将告诉 Mail 调用它自己的私有do_delivery方法。

ActionMailer 为其分配邮件程序类(即 MyMailer in class MyMailer < ActionMailer::Basesource,然后依赖于ActionMailer::Base的实现delivery_mail(除非您选择覆盖它)。

于 2014-08-28T20:15:24.693 回答