diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-06 18:36:27 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-06 18:36:27 -0700 |
commit | 842f27dd8227289ab4fd232bf89944584ad38fae (patch) | |
tree | 99b166dc1619b45e1a6da8c2bfe524c7e4f269e5 /actionmailer | |
parent | 4503926e4d0775bb8e3b1267e9341c0d7307cca9 (diff) | |
parent | edaa2c48179681efd96d0cad4b5dea696a2a31fb (diff) | |
download | rails-842f27dd8227289ab4fd232bf89944584ad38fae.tar.gz rails-842f27dd8227289ab4fd232bf89944584ad38fae.tar.bz2 rails-842f27dd8227289ab4fd232bf89944584ad38fae.zip |
Merge pull request #6950 from paneq/default_from2
Introduce config.action_mailer.default_options=
Allows to easily set :from, :replay_to, etc. options in
config/application.rb using simple syntax:
config.action_mailer.default_options = { from: "no-replay@example.org" }
Closes #6747
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 5 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 13 |
3 files changed, 19 insertions, 1 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 4d8f739403..177dc8109f 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -4,6 +4,8 @@ * Asynchronously send messages via the Rails Queue *Brian Cardarella* +* Set default Action Mailer options via config.action_mailer.default_options= *Robert Pankowecki* + ## Rails 3.2.5 (Jun 1, 2012) ## * No changes. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f31e1e007b..ea9a08102f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -421,6 +421,9 @@ module ActionMailer #:nodoc: self.default_params = default_params.merge(value).freeze if value default_params end + #Alias so that we can use it in config/application.rb which requires setters + #: config.action_mailer.default_options = {from: "no-replay@example.org"} + alias :default_options= :default # Receives a raw email, parses it into an email object, decodes it, # instantiates a new mailer, and passes the email object to the mailer @@ -786,4 +789,4 @@ module ActionMailer #:nodoc: ActiveSupport.run_load_hooks(:action_mailer, self) end -end
\ No newline at end of file +end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 144a6bfe39..9d1b1fda33 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -653,6 +653,19 @@ class BaseTest < ActiveSupport::TestCase assert_equal "Anonymous mailer body", mailer.welcome.body.encoded.strip end + test "default_from can be set" do + class DefaultFromMailer < ActionMailer::Base + default :to => 'system@test.lindsaar.net' + self.default_options = {from: "robert.pankowecki@gmail.com"} + + def welcome + mail(subject: "subject") + end + end + + assert_equal ["robert.pankowecki@gmail.com"], DefaultFromMailer.welcome.from + end + protected # Execute the block setting the given values and restoring old values after |