aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/actionmailer.gemspec2
-rw-r--r--actionmailer/lib/action_mailer/base.rb15
-rw-r--r--actionmailer/test/base_test.rb26
3 files changed, 42 insertions, 1 deletions
diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec
index 31d8efc7bf..13983aa663 100644
--- a/actionmailer/actionmailer.gemspec
+++ b/actionmailer/actionmailer.gemspec
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
s.has_rdoc = true
s.add_dependency('actionpack', '= 3.0.0.beta1')
- s.add_dependency('mail', '~> 2.1.2')
+ s.add_dependency('mail', '~> 2.1.3')
s.add_dependency('text-format', '~> 1.0.0')
end
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index ce13111850..e198543c34 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -181,6 +181,18 @@ module ActionMailer #:nodoc:
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
# with the filename +free_book.pdf+.
#
+ # = Observing and Intercepting Mails
+ #
+ # ActionMailer provides hooks into the Mail observer and interceptor methods. These allow you to
+ # register objects that are called during the mail delivery life cycle.
+ #
+ # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
+ # called once for every email sent after the email has been sent.
+ #
+ # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
+ # called before the email is sent, allowing you to make modifications to the email before it hits
+ # the delivery agents. Your object should make and needed modifications directly to the passed
+ # in Mail::Message instance.
#
# = Configuration options
#
@@ -265,6 +277,9 @@ module ActionMailer #:nodoc:
include ActionMailer::OldApi
include ActionMailer::DeprecatedApi
+
+ delegate :register_observer, :to => Mail
+ delegate :register_interceptor, :to => Mail
private_class_method :new #:nodoc:
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 5fc229df09..c1cf1f0157 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -502,6 +502,32 @@ class BaseTest < ActiveSupport::TestCase
mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer'])
assert_equal("Welcome from another path", mail.body.encoded)
end
+
+ # Before and After hooks
+
+ class MyObserver
+ def self.delivered_email(mail)
+ end
+ end
+
+ test "you can register an observer to the mail object that gets informed on email delivery" do
+ ActionMailer::Base.register_observer(MyObserver)
+ mail = BaseMailer.welcome
+ MyObserver.expects(:delivered_email).with(mail)
+ mail.deliver
+ end
+
+ class MyInterceptor
+ def self.delivering_email(mail)
+ end
+ end
+
+ test "you can register an interceptor to the mail object that gets passed the mail object before delivery" do
+ ActionMailer::Base.register_interceptor(MyInterceptor)
+ mail = BaseMailer.welcome
+ MyInterceptor.expects(:delivering_email).with(mail)
+ mail.deliver
+ end
protected