1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Allow to set default 'from' header of Devise mails in custom mailer class

This commit is contained in:
Szymon Przybył 2011-08-20 22:35:47 +02:00
parent b9413ab316
commit 7665cbf21d
7 changed files with 29 additions and 4 deletions

View file

@ -50,7 +50,9 @@ module Devise
end
def mailer_sender(mapping)
if Devise.mailer_sender.is_a?(Proc)
if default_params[:from].present?
default_params[:from]
elsif Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
@ -86,4 +88,4 @@ module Devise
end
end
end
end
end

View file

@ -2,7 +2,8 @@
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
# Configure the class responsible to send e-mails.

View file

@ -4,6 +4,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@ -35,6 +36,11 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View file

@ -4,6 +4,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@ -38,6 +39,11 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View file

@ -4,6 +4,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@ -38,6 +39,11 @@ class UnlockInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View file

@ -0,0 +1,3 @@
class Users::Mailer < Devise::Mailer
default :from => 'custom@example.com'
end

View file

@ -2,7 +2,8 @@
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Configure the class responsible to send e-mails.