From 6a8591525717821594e4ba7f0199b9a402b063db Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Tue, 26 Jun 2012 10:16:51 -0400 Subject: Guide update for Async ActionMailer --- guides/source/action_mailer_basics.textile | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/guides/source/action_mailer_basics.textile b/guides/source/action_mailer_basics.textile index ebe774fbef..7c61cc4a8d 100644 --- a/guides/source/action_mailer_basics.textile +++ b/guides/source/action_mailer_basics.textile @@ -457,6 +457,7 @@ The following configuration options are best made in one of the environment file |+delivery_method+|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.| |+perform_deliveries+|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.| |+deliveries+|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.| +|+async+|Setting this flag will turn on asynchronous message sending, message rendering and delivery will be pushed to Rails.queue for processing.| h4. Example Action Mailer Configuration @@ -514,3 +515,33 @@ end In the test we send the email and store the returned object in the +email+ variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect. + +h3. Asynchronous + +You can turn on application-wide asynchronous message sending by adding to your config/application.rb file: + + +config.action_mailer.async = true + + +Alternatively you can turn on async within specific mailers: + + +class WelcomeMailer < ActionMailer::Base + self.async = true +end + + +h4. Custom Queues + +If you need a different queue than Rails.queue for your mailer you can override ActionMailer::Base#queue: + + +class WelcomeMailer < ActionMailer::Base + def queue + MyQueue.new + end +end + + +Your custom queue should expect a job that responds to #run. -- cgit v1.2.3