ar_mailer

drbrain | Tue, 15 Aug 2006 23:39:00 GMT

Posted in ,

Rubyforge Project: http://rubyforge.org/projects/rctools

Documentation: http://dev.robotcoop.com/Tools/ar_mailer

About

Even deliviring email to the local machine may take too long when you have to send hundreds of messages. ar_mailer allows you to store messages into the database for later delivery by a separate process, ar_sendmail.

Installing ar_mailer

Just install the gem:

$ sudo gem install ar_mailer

Converting to ar_mailer

Go to your Rails project:

$ cd your_rails_project
Create a new migration:
$ ar_sendmail --create-migration
You'll need to redirect this into a file. If you want a different name provide the —table-name option. Create a new model:
$ ar_sendmail --create-model
You'll need to redirect this into a file. If you want a different name provide the —table-name option. Change your email classes to inherit from ActionMailer::ARMailer instead of ActionMailer::Base:
--- app/model/emailer.rb.orig   2006-08-10 13:16:33.000000000 -0700
+++ app/model/emailer.rb        2006-08-10 13:16:43.000000000 -0700
@@ -1,4 +1,4 @@
-class Emailer < ActionMailer::Base
+class Emailer < ActionMailer::ARMailer

def comment_notification(comment)
  from comment.author.email
Edit config/environments/production.rb and set the delivery agent:
$ grep delivery_method config/environments/production.rb
ActionMailer::Base.delivery_method = :activerecord
Run ar_sendmail:
$ ar_sendmail
You can also run ar_sendmail from cron with -o, or as a daemon with -d. See ar_sendmail -h for full details. comments

Comments RSS FEED

thanks for the neat hack.

But I’ve got “No rhtml, rxml, rjs or delegate template” error in production mode. Basically the ActionView::Base.base_path was screwed.

I moved the configs you put at config/environments/production.rb after my mailman.rb and it works

choonkeat said 9 days later

Yes, you’ve got to require ‘action_mailer/ar_mailer’ after the config block, otherwise the paths don’t get set correctly. You can set the mailer in the config block though, the initializer doesn’t care.

Eric Hodel said 21 days later

Comments are disabled