aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-25 00:37:12 +0100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-25 00:37:12 +0100
commite1c131863897390d04bd5515765236590747f2c1 (patch)
treea1bbe3b869ed48c16b7c259812e3d459e2188734 /actionmailer
parent48faf53be19c569e85f43a4dbfa63fe81618b09f (diff)
downloadrails-e1c131863897390d04bd5515765236590747f2c1.tar.gz
rails-e1c131863897390d04bd5515765236590747f2c1.tar.bz2
rails-e1c131863897390d04bd5515765236590747f2c1.zip
Added delivers_from.
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb14
-rw-r--r--actionmailer/test/base_test.rb9
2 files changed, 18 insertions, 5 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 84d50fa1f4..552fd7ccb8 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -273,6 +273,9 @@ module ActionMailer #:nodoc:
private_class_method :new #:nodoc:
+ extlib_inheritable_accessor :default_from
+ self.default_from = nil
+
extlib_inheritable_accessor :default_charset
self.default_charset = "utf-8"
@@ -298,6 +301,12 @@ module ActionMailer #:nodoc:
attr_writer :mailer_name
alias :controller_path :mailer_name
+ # Sets who is the default sender for the e-mail
+ def delivers_from(value = nil)
+ self.default_from = value if value
+ self.default_from
+ end
+
# Receives a raw email, parses it into an email object, decodes it,
# instantiates a new mailer, and passes the email object to the mailer
# object's +receive+ method. If you want your mailer to be able to
@@ -318,7 +327,7 @@ module ActionMailer #:nodoc:
end
# TODO The delivery should happen inside the instrument block
- def delivered_email(mail)
+ def delivered_email(mail) #:nodoc:
ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload|
self.set_payload_for_mail(payload, mail)
end
@@ -387,8 +396,9 @@ module ActionMailer #:nodoc:
charset = headers[:charset] || m.charset || self.class.default_charset.dup
mime_version = headers[:mime_version] || m.mime_version || self.class.default_mime_version.dup
- # Set subjects and fields quotings
+ # Set fields quotings
headers[:subject] ||= default_subject
+ headers[:from] ||= self.class.default_from.dup
quote_fields!(headers, charset)
# Render the templates and blocks
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index b8d21132de..d8616ee3be 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -1,16 +1,14 @@
# encoding: utf-8
require 'abstract_unit'
-# class Notifier < ActionMailer::Base
-# delivers_from 'notifications@example.com'
class BaseTest < ActiveSupport::TestCase
DEFAULT_HEADERS = {
:to => 'mikel@test.lindsaar.net',
- :from => 'jose@test.plataformatec.com',
:subject => 'The first email on new API!'
}
class BaseMailer < ActionMailer::Base
+ delivers_from 'jose@test.plataformatec.com'
self.mailer_name = "base_mailer"
def welcome(hash = {})
@@ -72,6 +70,11 @@ class BaseTest < ActiveSupport::TestCase
assert_equal(email.subject, 'The first email on new API!')
end
+ test "mail() with from overwrites the class level default" do
+ email = BaseMailer.welcome(:from => 'someone@else.com').deliver
+ assert_equal(email.from, ['someone@else.com'])
+ end
+
test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
@time = Time.now
email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net',