Plugins - Mail Queue
Add to favoritesMailQueue
===========
Want to send out your mail asynchronously without having to touch any code that uses the Action Mailer?
With the plugin installed, all mail send from Mailer gets put into a table called QueuedMails. Here's my migration to add that table:
class AddQueuedMailTable < ActiveRecord::Migration
def self.up
create_table :queued_mails do |t|
t.column :object, :text
t.column :mailer, :string
end
end
def self.down
drop_table :queued_mails
end
end
Now everytime you call YouMailer.deliver_something(*params), that mail object will be stored in the QueuedMails table. Just periodically call script/runner from a cron job to process your new mail queue:
"script/runner 'MailQueue.process' -e production"
If you want to bypass the queue just called the deliver_method_name with an exclamation point at the end. Like:
YouMailer.deliver_something!(*params)
WARNING:
This feature to bypass the queue isn't the same way it was done in the original release of this plugin, so it isn't backwards compatible. Not a huge thing to change, and it probably wasn't a very popular thing used by people using this plugin anyways.
-Nate
Inkling Inc.
http://www.inklingmarkets.com
http://code.google.com/p/mail-queue/
http://mail-queue.googlecode.com/svn/mail_queue
Rails' (MIT)
Model

I've moved the mail_queue to a google repos. The directory's name was changed to make installing the plugin a no brainer since it will install with the correct name now.
I've tested a bit with attachments, even updated the tests in this plugin to send the Google logo as an attachment and it still works great as is. Can someone create a test case that I can add to this plugin that replicates where attachments don't work please?
Gwyn, thanks for trying to help everyone out. A couple things I noticed though of the MailTrain is that the parameters you expect people to be using have to be simple Ruby types. I believe this won't work when you try to pass down say ActiveRecord objects down into the mail templates. I had this same problem trying to serialize stuff for another asynch plugin I've worked on.
Also, I still prefer this plugins method of not making people alter their current code to have the joy of sending asynchronous mail. But it still includes a way to bypass the thing to send synchronously.
This plugin seems like a pretty good concept so I'd love to be able to figure out with you guys' help where it doesn't work.
I can confirm Robert's problem with attachments. I hacked together a simple replacement: http://gwyn.dezyne.net/page/mailtrain
Your plugin looks great, and I would love to use it. However, it fails for me in a special case: when I have e-mails with attachments, the TMail::Mail object is not unserialized correctly and ActionMailer fails to send it (It works fine when my e-mail is not serialized). I get this error msg: The error occurred while evaluating nil.empty? from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/mail.rb:94:in
accept' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/mail.rb:131:inwithmultipartencoding' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/mail.rb:128:ineach' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/mail.rb:128:inwithmultipartencoding' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/mail.rb:94:inaccept' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/encode.rb:66:inaccept_strategy' from /usr/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/vendor/tmail/encode.rb:55:inencoded' from ./script/../config/../vendor/plugins/mail_queue/lib/mail_queue.rb:24:indeliver!'Have you experienced it? Any ideas of how to solve it? Thanx Robert
Yup, this was written awhile ago, and yes I would edit it with an alias now. Also someone brought to my attention that if this plugin is installed from subversion it will install as "mail-queue" in your vendor dir. You will have to rename it to "mail_queue" for this to work right.
Soon, I should clean this thing up and host it at google's subversion repos.
Thanks for taking a look at it and commenting on it.
Hello,
In your code you ask: "Is there a better way to override this behavior but then get at it again from non-queue mode?"
I would suggest the following:
Create an alias for the original method
alias deliver! nonqueuedeliver!
Overwrite it...
def deliver!(mail = @mail) if queue # code... else nonqueuedeliver!(mail) end end
GJ for the plugin, its very simple and REALLY useful, since the web server won't get stuck while sending mails. ;)