Logo: Relish

  1. Sign in

Project: Dj-mailer



Build Status

This gem allows you to send emails asyncronously via delayed_job_active_record
without modifying the existing codebase, keeping the standard action mailer

Currenlty delayed_job_active_record requires that you replace all your email
deliver calls as follows:

  # without delayed job

  # with delayed job

By adding this gem in your gemfile all your current emails will be automatically
handled by delayed job without any interface change. At the moment you have
to setup the delayed job environment on your own running the migrations for the


Add this line to your application's Gemfile:

  gem 'dj_mailer'

And then execute: bundle

Or install it yourself as:

  gem install dj_mailer


Delayed e-mails is an awesome thing in production environments, but for e-mail specs/tests in testing environments it can be a mess causing specs/tests to fail because the e-mail haven't been sent directly. Therefore you can configure what environments that should be excluded like so:

  # config/initializers/dj_mailer.rb

  DjMailer::Delayable.excluded_environments = [:test, :cucumber]  # etc.




to run the specs:

  bundle exec rake spec

to run the cucumber features:

  bundle exec rake cucumber

Sample delay job migration

Just a reminder I have to add the generator (via rails you can simply run rails generate delayed_job:active_record)

class CreateDelayedJobs < ActiveRecord::Migration
  def self.up
      table.datetime :run_at                       # When to run. Could be Time.zone.now for immediately, or sometime in the future.

    add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'

  def self.down
    drop_table :delayed_jobs


  1. Fork it
  3. Add your feature tests to the rspec/cucumber test suite
  4. Commit your changes (git commit -am 'Added some feature')
  6. Create new Pull Request


  1. deliver email asyncronously with delayed_job

Last published over 4 years ago by spaghetticode.