ActionMailer Interceptorとは
Railsの標準機能です。追加のgemをインストールする必要はなく、Railsのデフォルト機能として利用できます。
ActionMailer Interceptorは、メールが実際に送信される前に、そのメールの内容を変更するための機能です。たとえば、メールの件名を変更したり、送信先を別のアドレスに変更したりすることができます。
Interceptorの設定方法
「app/mailers/interceptors/email_interceptor.rb」を手動で作成します。
class MailInterceptor
def self.delivering_email(message)
message.to = ENV['TEST_NOTICE_MAIL']
end
end
「config/initializers/mail_interceptors.rb」にを設定します。
class MailInterceptor
def self.delivering_email(message)
message.to = ENV['TEST_NOTICE_MAIL']
end
end
これでメール送信時には自動的に「TEST_NOTICE_MAIL」のアドレスへメールを送信するように設定できました。