Skip to content

Commit

Permalink
Guide update for Async ActionMailer
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jun 26, 2012
1 parent dc9f6fc commit 6a85915
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions guides/source/action_mailer_basics.textile
Expand Up @@ -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 <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:file</tt> and <tt>:test</tt>.| |+delivery_method+|Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:file</tt> and <tt>:test</tt>.|
|+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.| |+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.| |+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 <tt>Rails.queue</tt> for processing.|


h4. Example Action Mailer Configuration h4. Example Action Mailer Configuration


Expand Down Expand Up @@ -514,3 +515,33 @@ end
</ruby> </ruby>


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. 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 <tt>config/application.rb</tt> file:

<ruby>
config.action_mailer.async = true
</ruby>

Alternatively you can turn on async within specific mailers:

<ruby>
class WelcomeMailer < ActionMailer::Base
self.async = true
end
</ruby>

h4. Custom Queues

If you need a different queue than <tt>Rails.queue</tt> for your mailer you can override <tt>ActionMailer::Base#queue</tt>:

<ruby>
class WelcomeMailer < ActionMailer::Base
def queue
MyQueue.new
end
end
</ruby>

Your custom queue should expect a job that responds to <tt>#run</tt>.

0 comments on commit 6a85915

Please sign in to comment.