Asynchronously send mail using ActionMailer and Que.
So far, this has been tested only in Rails 4.
Que is an alternative DelayedJob or QueueClassic and is a queue for Ruby. It uses PostgreSQL's [advisory locks] (http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS) to manage jobs. See the que repo for more details.
- Que-Mailer uses Postgres rather than Redis, RabbitMQ or other message queue. If you already have Postgres on a project, now you have 1 fewer dependency!
- Que-Mailer can create background workers within your existing process. This means, for instance, that your background workers and web server can share a Heroku dyno. It also means that you don't have to remember to launch separate workers.
- All of the benefits of using advisory locks and Postgres (like safety, security, and atomic backups.)
Que and Que-Mailer are fairly new compared to other queue solutions. We're still finding bugs and have only tested in a limited set of configurations.
If you have problems, please post an issue.
Right now it is best to use the github master version.
Add this line to your application's Gemfile:
gem 'que_mailer', :git => 'git://github.com/prehnRA/que-mailer.git', :branch => 'master'
And then execute:
$ bundle
Additionally, you need to follow the steps for installing and using Que. Remember to:
$ rails generate que:install
$ rake db:migrate
Which will get your database ready to store jobs.
You use Que-Mailer by including it in your mailers, like this:
class ExampleMailer < ActionMailer::Base
include Que::Mailer
default from: '[email protected]'
def example_message(*args)
@args = *args
mail(to: "[email protected]", subject: "Hello World")
end
end
Then,
ExampleMailer.example_message.deliver
will send mail using the background workers.
ExampleMailer.example_message.deliver!
will bypass Que and send the mail directly.
Additionally, you can schedule mail to be sent at a later time.
ExampleMailer.deliver_in(2.days)
will send an email two days from now.
ExampleMailer.deliver_at(time)
will deliver the email at time
.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
You can also help by testing this in your application and reporting any issues you encounter.
MIT