mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Address issue #1936
Update mailer to accept reply_to as a default param as well, as discussed in https://github.com/plataformatec/devise/issues/1936#issuecomment-6583637
This commit is contained in:
parent
f94b71038e
commit
d1bf31729d
3 changed files with 26 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue