Skip to content
Browse files

Merge pull request #1954 from mrchrisadams/d1bf31729d10fbb65f1b7ce158…

…f3926aa946b3ad

Allow setting of default reply_to fields on mailer mails - #1936
  • Loading branch information...
2 parents a89a205 + d1bf317 commit 9678b422ff36f800377742f98c654cb001ea2482 @josevalim josevalim committed
View
21 lib/devise/mailers/helpers.rb
@@ -28,8 +28,9 @@ def devise_mapping
def headers_for(action)
headers = {
:subject => translate(devise_mapping, action),
- :from => mailer_sender(devise_mapping),
:to => resource.email,
+ :from => mailer_sender(devise_mapping),
+ :reply_to => mailer_reply_to(devise_mapping),
:template_path => template_paths
}
@@ -37,16 +38,20 @@ def headers_for(action)
headers.merge!(resource.headers_for(action))
end
- unless headers.key?(:reply_to)
- headers[:reply_to] = headers[:from]
- end
-
headers
end
- def mailer_sender(mapping)
- if default_params[:from].present?
- default_params[:from]
+ def mailer_reply_to(mapping)
+ mailer_sender(mapping, :reply_to)
+ end
+
+ def mailer_from(mapping)
+ mailer_sender(mapping, :from)
+ end
+
+ def mailer_sender(mapping, sender = :from)
+ if default_params[sender].present?
+ default_params[sender]
elsif Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
View
7 test/mailers/confirmation_instructions_test.rb
@@ -50,6 +50,13 @@ def mail
assert_equal ['test@example.com'], mail.reply_to
end
+ test 'setup reply to as different if set in defaults' do
+ Devise.mailer = 'Users::ReplyToMailer'
+ assert_equal ['custom@example.com'], mail.from
+ assert_equal ['custom_reply_to@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
View
7 test/rails_app/app/mailers/users/mailer.rb
@@ -1,3 +1,8 @@
class Users::Mailer < Devise::Mailer
- default :from => 'custom@example.com'
+ default :from => 'custom@example.com'
end
+
+class Users::ReplyToMailer < Devise::Mailer
+ default :from => 'custom@example.com'
+ default :reply_to => 'custom_reply_to@example.com'
+end

0 comments on commit 9678b42

Please sign in to comment.
Something went wrong with that request. Please try again.