diff --git a/app/mailers/devise/mailer.rb b/app/mailers/devise/mailer.rb index faa63c01..ade51ca9 100644 --- a/app/mailers/devise/mailer.rb +++ b/app/mailers/devise/mailer.rb @@ -13,25 +13,24 @@ class Devise::Mailer < ::ActionMailer::Base def unlock_instructions(record) setup_mail(record, :unlock_instructions) end - + private - + # Configure default email options def setup_mail(record, action) - initialize_from_record record - + initialize_from_record(record) mail headers_for(action) end - + def initialize_from_record(record) @scope_name = Devise::Mapping.find_scope!(record) @resource = instance_variable_set("@#{devise_mapping.name}", record) end - + def devise_mapping @devise_mapping ||= Devise.mappings[scope_name] end - + def headers_for(action) headers = { :subject => translate(devise_mapping, action), @@ -39,11 +38,15 @@ class Devise::Mailer < ::ActionMailer::Base :to => resource.email, :template_path => template_paths } - + if resource.respond_to?(:headers_for) headers.merge!(resource.headers_for(action)) end - + + unless headers.key?(:reply_to) + headers[:reply_to] = headers[:from] + end + headers end diff --git a/test/mailers/confirmation_instructions_test.rb b/test/mailers/confirmation_instructions_test.rb index 083cc279..970fdf1d 100644 --- a/test/mailers/confirmation_instructions_test.rb +++ b/test/mailers/confirmation_instructions_test.rb @@ -35,6 +35,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase assert_equal ['test@example.com'], mail.from end + test 'setup reply to as copy from sender' do + assert_equal ['test@example.com'], mail.reply_to + end + test 'setup subject from I18n' do store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do assert_equal 'Account Confirmation', mail.subject diff --git a/test/mailers/reset_password_instructions_test.rb b/test/mailers/reset_password_instructions_test.rb index e2c798b5..cd7ecb19 100644 --- a/test/mailers/reset_password_instructions_test.rb +++ b/test/mailers/reset_password_instructions_test.rb @@ -38,6 +38,10 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase assert_equal ['test@example.com'], mail.from end + test 'setup reply to as copy from sender' do + assert_equal ['test@example.com'], mail.reply_to + end + test 'setup subject from I18n' do store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do assert_equal 'Reset instructions', mail.subject diff --git a/test/mailers/unlock_instructions_test.rb b/test/mailers/unlock_instructions_test.rb index 38bf9d6f..6900ccdb 100644 --- a/test/mailers/unlock_instructions_test.rb +++ b/test/mailers/unlock_instructions_test.rb @@ -38,6 +38,10 @@ class UnlockInstructionsTest < ActionMailer::TestCase assert_equal ['test@example.com'], mail.from end + test 'setup reply to as copy from sender' do + assert_equal ['test@example.com'], mail.reply_to + end + test 'setup subject from I18n' do store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do assert_equal 'Yo unlock instructions', mail.subject