Skip to content

Commit

Permalink
Définir no-reply expéditeur pour les mails devise User
Browse files Browse the repository at this point in the history
  • Loading branch information
adipasquale committed Dec 16, 2024
1 parent eafdda6 commit 9117621
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/mailers/custom_devise_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class CustomDeviseMailer < Devise::Mailer
helper :application
default template_path: "devise/mailer"

after_action :set_no_reply_for_users

def invitation_instructions(record, token, opts = {})
@token = token
@user_params = opts[:user_params] || {}
Expand All @@ -21,6 +23,15 @@ def invitation_instructions(record, token, opts = {})

private

def set_no_reply_for_users
if @resource.is_a?(User)
mail.from = rfc5322_name_and_email(
"Ne pas répondre - #{domain.name}",
"ne-pas-repondre@#{domain.reply_host_name}"
)
end
end

def domain
resource.domain
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
fill_in "user_email", with: user.email
click_on "Envoyer"
open_email(user.email)
expect(current_email.base.email[:from].to_s).to eq(%("RDV Aide Numérique" <support@rdv-aide-numerique.fr>))
expect(current_email.base.email[:from].to_s).to eq(%("Ne pas répondre - RDV Aide Numérique" <ne-pas-repondre@reply.rdv-aide-numerique-test.localhost>))
expect(current_email.html_part.body.to_s).to include('<a href="http://www.rdv-aide-numerique-test.localhost/users/password/edit?reset_password_token=')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/custom_devise_mailer_domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def expect_to_use_domain(domain)
expect(sent_email.body).to include(domain.host_name)
expect(sent_email[:from].unparsed_value).to match(%("#{domain.name}" <#{domain.support_email}>))
expect(sent_email[:from].unparsed_value).to match(%("Ne pas répondre - #{domain.name}" <ne-pas-repondre@#{domain.reply_host_name}>))
end

context "when user has no RDV" do
Expand Down

0 comments on commit 9117621

Please sign in to comment.