diff --git a/app/mailers/concerns/balanced_delivery_concern.rb b/app/mailers/concerns/balanced_delivery_concern.rb index 486aadac4..3bbeb6d7e 100644 --- a/app/mailers/concerns/balanced_delivery_concern.rb +++ b/app/mailers/concerns/balanced_delivery_concern.rb @@ -8,6 +8,10 @@ module BalancedDeliveryConcern self.class.critical_email?(action_name) end + def bypass_unverified_mail_protection! + headers[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION] = true + end + private def forced_delivery_provider? diff --git a/app/mailers/devise_user_mailer.rb b/app/mailers/devise_user_mailer.rb index d9acb25c3..26cad7c03 100644 --- a/app/mailers/devise_user_mailer.rb +++ b/app/mailers/devise_user_mailer.rb @@ -34,6 +34,8 @@ class DeviseUserMailer < Devise::Mailer @procedure = opts[:procedure_after_confirmation] || nil @prefill_token = opts[:prefill_token] + bypass_unverified_mail_protection! + I18n.with_locale(record.locale) do super end diff --git a/spec/lib/balancer_delivery_method_spec.rb b/spec/lib/balancer_delivery_method_spec.rb index 36c691195..659adb46e 100644 --- a/spec/lib/balancer_delivery_method_spec.rb +++ b/spec/lib/balancer_delivery_method_spec.rb @@ -1,20 +1,23 @@ RSpec.describe BalancerDeliveryMethod do class ExampleMailer < ApplicationMailer + include BalancedDeliveryConcern + def greet(name, bypass_unverified_mail_protection: true) mail(to: name, from: "smtp_from", body: "Hello #{name}") - if bypass_unverified_mail_protection - headers['BYPASS_UNVERIFIED_MAIL_PROTECTION'] = true - end + bypass_unverified_mail_protection! if bypass_unverified_mail_protection end end class ImportantEmail < ApplicationMailer + include BalancedDeliveryConcern + before_action :set_x_deliver_with def greet(name) mail(to: name, from: "smtp_from", body: "Hello #{name}") - headers['BYPASS_UNVERIFIED_MAIL_PROTECTION'] = true + + bypass_unverified_mail_protection! end private diff --git a/spec/mailers/devise_user_mailer_spec.rb b/spec/mailers/devise_user_mailer_spec.rb index ed0e946ff..88fd2c21c 100644 --- a/spec/mailers/devise_user_mailer_spec.rb +++ b/spec/mailers/devise_user_mailer_spec.rb @@ -5,7 +5,10 @@ RSpec.describe DeviseUserMailer, type: :mailer do subject { described_class.confirmation_instructions(user, token, opts = {}) } context 'without SafeMailer configured' do - it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) } + it do + expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) + expect(subject[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION]).to be_present + end end context 'with SafeMailer configured' do