diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 77645856b..44fab5d6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base + include MailerDolistConcern include MailerMonitoringConcern helper :application # gives access to all helpers defined within `application_helper`. diff --git a/app/mailers/concerns/mailer_dolist_concern.rb b/app/mailers/concerns/mailer_dolist_concern.rb new file mode 100644 index 000000000..6db7c74d7 --- /dev/null +++ b/app/mailers/concerns/mailer_dolist_concern.rb @@ -0,0 +1,15 @@ +module MailerDolistConcern + extend ActiveSupport::Concern + + included do + before_action :add_dolist_header + + # mandatory for dolist + # used for tracking in Dolist UI + # the delivery_method is yet unknown (:balancer) + # so we add the dolist header for everyone + def add_dolist_header + headers['X-Dolist-Message-Name'] = action_name + end + end +end diff --git a/app/mailers/concerns/mailer_monitoring_concern.rb b/app/mailers/concerns/mailer_monitoring_concern.rb index 849b6f016..6cbd60247 100644 --- a/app/mailers/concerns/mailer_monitoring_concern.rb +++ b/app/mailers/concerns/mailer_monitoring_concern.rb @@ -2,8 +2,6 @@ module MailerMonitoringConcern extend ActiveSupport::Concern included do - before_action :add_dolist_header - # Intercept & log any error, then re-raise so job will retry. # NOTE: rescue_from order matters, later matchers are tried first. rescue_from StandardError, with: :log_and_raise_delivery_error @@ -21,14 +19,6 @@ module MailerMonitoringConcern end end - # mandatory for dolist - # used for tracking in Dolist UI - # the delivery_method is yet unknown (:balancer) - # so we add the dolist header for everyone - def add_dolist_header - headers['X-Dolist-Message-Name'] = action_name - end - def log_and_raise_delivery_error(exception) EmailEvent.create_from_message!(message, status: "dispatch_error") Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject }) diff --git a/app/mailers/devise_user_mailer.rb b/app/mailers/devise_user_mailer.rb index f26bb73ea..f9a940cb2 100644 --- a/app/mailers/devise_user_mailer.rb +++ b/app/mailers/devise_user_mailer.rb @@ -3,6 +3,7 @@ class DeviseUserMailer < Devise::Mailer helper :application # gives access to all helpers defined within `application_helper`. helper MailerHelper include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url` + include MailerDolistConcern include MailerMonitoringConcern layout 'mailers/layout' before_action :add_delivery_method, if: :forced_delivery?