mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Add reply-to to e-mail headers by default. Closes #474
This commit is contained in:
parent
29e9be92b0
commit
ff0b4deb1a
4 changed files with 24 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue