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)
|
def unlock_instructions(record)
|
||||||
setup_mail(record, :unlock_instructions)
|
setup_mail(record, :unlock_instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Configure default email options
|
# Configure default email options
|
||||||
def setup_mail(record, action)
|
def setup_mail(record, action)
|
||||||
initialize_from_record record
|
initialize_from_record(record)
|
||||||
|
|
||||||
mail headers_for(action)
|
mail headers_for(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_from_record(record)
|
def initialize_from_record(record)
|
||||||
@scope_name = Devise::Mapping.find_scope!(record)
|
@scope_name = Devise::Mapping.find_scope!(record)
|
||||||
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
||||||
end
|
end
|
||||||
|
|
||||||
def devise_mapping
|
def devise_mapping
|
||||||
@devise_mapping ||= Devise.mappings[scope_name]
|
@devise_mapping ||= Devise.mappings[scope_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def headers_for(action)
|
def headers_for(action)
|
||||||
headers = {
|
headers = {
|
||||||
:subject => translate(devise_mapping, action),
|
:subject => translate(devise_mapping, action),
|
||||||
|
@ -39,11 +38,15 @@ class Devise::Mailer < ::ActionMailer::Base
|
||||||
:to => resource.email,
|
:to => resource.email,
|
||||||
:template_path => template_paths
|
:template_path => template_paths
|
||||||
}
|
}
|
||||||
|
|
||||||
if resource.respond_to?(:headers_for)
|
if resource.respond_to?(:headers_for)
|
||||||
headers.merge!(resource.headers_for(action))
|
headers.merge!(resource.headers_for(action))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless headers.key?(:reply_to)
|
||||||
|
headers[:reply_to] = headers[:from]
|
||||||
|
end
|
||||||
|
|
||||||
headers
|
headers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
||||||
assert_equal ['test@example.com'], mail.from
|
assert_equal ['test@example.com'], mail.from
|
||||||
end
|
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
|
test 'setup subject from I18n' do
|
||||||
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
||||||
assert_equal 'Account Confirmation', mail.subject
|
assert_equal 'Account Confirmation', mail.subject
|
||||||
|
|
|
@ -38,6 +38,10 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
||||||
assert_equal ['test@example.com'], mail.from
|
assert_equal ['test@example.com'], mail.from
|
||||||
end
|
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
|
test 'setup subject from I18n' do
|
||||||
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do
|
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do
|
||||||
assert_equal 'Reset instructions', mail.subject
|
assert_equal 'Reset instructions', mail.subject
|
||||||
|
|
|
@ -38,6 +38,10 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
||||||
assert_equal ['test@example.com'], mail.from
|
assert_equal ['test@example.com'], mail.from
|
||||||
end
|
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
|
test 'setup subject from I18n' do
|
||||||
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
|
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
|
||||||
assert_equal 'Yo unlock instructions', mail.subject
|
assert_equal 'Yo unlock instructions', mail.subject
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue