diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 83e7530d5..e28f9f1f8 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -15,16 +15,16 @@ class ApplicationMailer < Mail::Notify::Mailer # # @see https://github.com/rails/rails/issues/39018 if respond_to?(:headers) - recipient_email = headers["To"].value - MailDeliveryFailure.create!(recipient_email:) + email_address = headers["To"].value + mailer_action_method = action_name + mailer_class = mailer_name + MailDeliveryFailure.create!(email_address:, mailer_action_method:, mailer_class:) end raise end def notify_email(headers) - headers = - headers.merge(rails_mailer: mailer_name, rails_mail_template: action_name) view_mail(GOVUK_NOTIFY_TEMPLATE_ID, headers) end end diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index a786e60c7..b19a89633 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -27,7 +27,11 @@ def test_notify_error Notifications::Client::NotFoundError, ) - expect(Email.last.delivery_status).to eql("notify_error") + failure = MailDeliveryFailure.last + expect(failure).not_to be_nil + expect(failure.email_address).to eq("test@example.com") + expect(failure.mailer_action_method).to eq("test_notify_error") + expect(failure.mailer_class).to eq("anonymous") end end end