3
3

ActionMailer Interceptorの設定

Posted at

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」のアドレスへメールを送信するように設定できました。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3