diff --git a/app/mailers/invite_mailer.rb b/app/mailers/invite_mailer.rb index d9c892b91..a769d5458 100644 --- a/app/mailers/invite_mailer.rb +++ b/app/mailers/invite_mailer.rb @@ -28,6 +28,8 @@ class InviteMailer < ApplicationMailer @invite = invite email = invite.email + configure_defaults_for_email(email) + mail(to: email, subject: subject, reply_to: reply_to) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 0989b41c6..f45892699 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -9,6 +9,8 @@ class UserMailer < ApplicationMailer @subject = "Demande de création de compte" @procedure = procedure + configure_defaults_for_user(user) + mail(to: user.email, subject: @subject, procedure: @procedure) end @@ -17,6 +19,8 @@ class UserMailer < ApplicationMailer @requested_email = requested_email @subject = "Fusion de compte" + configure_defaults_for_email(requested_email) + mail(to: requested_email, subject: @subject) end @@ -25,6 +29,8 @@ class UserMailer < ApplicationMailer @email_merge_token_created_at = email_merge_token_created_at @subject = "Veuillez confirmer la fusion de compte" + configure_defaults_for_email(email) + mail(to: email, subject: @subject) end @@ -33,9 +39,11 @@ class UserMailer < ApplicationMailer @user = user subject = "Activez votre compte instructeur" + configure_defaults_for_user(user) + mail(to: user.email, subject: subject, - reply_to: CONTACT_EMAIL) + reply_to: Current.contact_email) end def invite_gestionnaire(user, reset_password_token, groupe_gestionnaire) @@ -44,12 +52,16 @@ class UserMailer < ApplicationMailer @groupe_gestionnaire = groupe_gestionnaire subject = "Activez votre compte gestionnaire" + configure_defaults_for_user(user) + mail(to: user.email, subject: subject, - reply_to: CONTACT_EMAIL) + reply_to: Current.contact_email) end def send_archive(administrateur_or_instructeur, procedure, archive) + configure_defaults_for_user(administrateur_or_instructeur.user) + @archive = archive @procedure = procedure @archive_url = case administrateur_or_instructeur @@ -71,6 +83,8 @@ class UserMailer < ApplicationMailer @user = user @subject = "Votre compte sera supprimé dans #{Expired::REMAINING_WEEKS_BEFORE_EXPIRATION} semaines" + configure_defaults_for_user(user) + mail(to: user.email, subject: @subject) end @@ -80,6 +94,8 @@ class UserMailer < ApplicationMailer @procedure = procedure @content = content + configure_defaults_for_user(user) + mail(to: user.email, subject: @subject, content: @content, procedure: @procedure) end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 3bd017852..0ae0bc594 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -13,7 +13,16 @@ RSpec.describe UserMailer, type: :mailer do subject { described_class.new_account_warning(user, procedure) } - it { expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path)) } + it { expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path, host: ENV.fetch("APP_HOST_LEGACY"))) } + + context "when user has preferred domain" do + let(:user) { create(:user, preferred_domain: :demarches_gouv_fr) } + + it do + expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path, host: ENV.fetch("APP_HOST"))) + expect(header_value("From", subject)).to include("@demarches.gouv.fr") + end + end end context 'without SafeMailer configured' do @@ -65,7 +74,7 @@ RSpec.describe UserMailer, type: :mailer do subject { described_class.france_connect_merge_confirmation(email, code, 15.minutes.from_now) } it { expect(subject.to).to eq([email]) } - it { expect(subject.body).to include(france_connect_particulier_mail_merge_with_existing_account_url(email_merge_token: code)) } + it { expect(subject.body).to include(france_connect_particulier_mail_merge_with_existing_account_url(email_merge_token: code))) } context 'without SafeMailer configured' do it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) } @@ -92,15 +101,15 @@ RSpec.describe UserMailer, type: :mailer do context 'instructeur' do let(:role) { create(:instructeur) } it { expect(subject.to).to eq([role.user.email]) } - it { expect(subject.body).to have_link('Consulter mes archives', href: instructeur_archives_url(procedure)) } - it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: instructeur_procedure_url(procedure)) } + it { expect(subject.body).to have_link('Consulter mes archives', href: instructeur_archives_url(procedure, host: ENV.fetch("APP_HOST_LEGACY"))) } + it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: instructeur_procedure_url(procedure, host: ENV.fetch("APP_HOST_LEGACY"))) } end context 'instructeur' do let(:role) { create(:administrateur) } it { expect(subject.to).to eq([role.user.email]) } - it { expect(subject.body).to have_link('Consulter mes archives', href: admin_procedure_archives_url(procedure)) } - it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: admin_procedure_url(procedure)) } + it { expect(subject.body).to have_link('Consulter mes archives', href: admin_procedure_archives_url(procedure, host: ENV.fetch("APP_HOST_LEGACY"))) } + it { expect(subject.body).to have_link("#{procedure.id} − #{procedure.libelle}", href: admin_procedure_url(procedure, host: ENV.fetch("APP_HOST_LEGACY"))) } end context 'when perform_later is called' do