Merge pull request #1954 from mrchrisadams/d1bf31729d10fbb65f1b7ce158f3926aa946b3ad

Allow setting of default reply_to fields on mailer mails - #1936
This commit is contained in:
José Valim 2012-06-27 03:19:52 -07:00
commit 9678b422ff
3 changed files with 26 additions and 9 deletions

View File

@ -28,8 +28,9 @@ module Devise
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 @@ module Devise
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 File

@ -50,6 +50,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
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 File

@ -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