Topic: ar_mailer

I'm working on a project that will be sending emails on a regular basis (monthly or weekly) to a mailing list that will (hopefully) become rather large with time. Obviously calling the deliver_xxx method for every email would be too much and take too long--especially if the user is waiting for all the emails to be sent before the page will be rendered.

I checked out Eric Hodel's ar_mailer gem; I glanced over the documentation and it seems to be exactly what I need.

Anybody have any experience with ar_mailer? If so, any tips on how to implement it would be much appreciated?

thanks.

Re: ar_mailer

Hey thanks Phil that worked and saved my neck!. Any ways thanks for your prompt reply. One quick question though. Can I have part of my application send emails queued in the table emails and the other have sent mails directly.
Since I configured my environment.rb to

ActionMailer::Base.delivery_method = :activerecord

The methods that I send emails directly gives out an error stating undefined method as I have changed the environment.rb
from :smtp to :activerecord to send the queued mails

. Thanks in advance.

Re: ar_mailer

Well, I haven't tried it myself, but in theory I think it should be possible.

Glancing at the ar_mailer documentation (http://seattlerb.rubyforge.org/ar_mailer/), the ActionMailer::ARSendmail class exposes a public instance method named deliver which accepts a collection of email objects as it's only argument and then sends those emails using the SMTP settings you've set in your environment file. Basically, when you run the ar_sendmail command (either from cron or the command line or whatever) it I'm pretty sure it eventually calls the deliver method to do its dirty work.

So, you could have a callback (i.e. after_create) that would call the deliver method manually only on the emails you want to send immediately. Make sense? Be sure to send a collection of emails (even if the collection is only one email long) to the method, because that's what it expects -- it uses methods like Array#shift which will throw an error if called on something other than some sort of collection.

Anyway, I haven't actually tried this, I'm just theorizing here, so your mileage may vary. Let me know what you figure out, and if I get some free time I may dig a bit deeper and test what I've just suggested to you. Also, check out the documentation to see if it's of any help.