Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Capistrano Deployment Email Notification
Ruby CSS

This branch is 15 commits ahead, 67 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


A Gem For Capistrano Deployment Email Notification

Project Capistrano Mailer
gem name capistrano_mailer
license MIT
moldiness Maintainer Status
version Gem Version
dependencies Dependency Status
code quality Code Climate
inline documenation Inline docs
continuous integration Build Status
test coverage Coverage Status
author Peter Boling
Spread ~♡ⓛⓞⓥⓔ♡~ Endorse Me


  • It is a Capistrano Plugin / Ruby Gem that requires ActionMailer
  • It is MIT licensed
  • It is old, but still kicking; project started in 2007
  • rails2 branch (THIS BRANCH!), releases will be in 3.x range, requires Rails 2.X
  • master branch, releases will be in 4.x range, requires Rails 3.X
  • Requires at least Capistrano 2.4.3 (might work with capistrano as old as 2.1.0, but has not been tested)
  • Known to be compatible with SCMs as of version 3.1.2: Perforce, SVN, and Git
  • Known to be compatible with, but does not require, the deprec gem.


Ever wanted to be emailed whenever someone on the team does a cap deploy of trunk or some tag to some server. Wouldn't it be nice to know about it every time a release was deployed? For large rails projects this type of coordination is essential, and this plugin makes sure everyone on the need to know list is notified when something new is deployed.

This plugin/gem is an extension to Capistrano.

That means it registers itself with Capistrano as a plugin and is therefore available to call in your recipes.

If you are looking to roll your own email integration into capistrano then try this pastie: (thanks to Mislav Marohnić). But if you want to take the easy road to riches then keep reading ;) -- figurative "riches" of course, I promise nothing in return for your using this plugin

Important Note:

The first time you deploy to a server (a 'cold' deploy) capistrano mailer will cause an error because it uses capistrano's previous release variables, and when there are no previous releases capistrano throws an error. In the next version this will be fixed, just don't have time at the moment. If you would like to work on this 'first deploy' problem please fork my repo and work on it!


Add this line to your application's Gemfile:

gem 'capistrano_mailer', '~> 3.3.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano_mailer

With Rails <= 2.X (THIS BRANCH!)

The 3.x+ versions of this gem require Rails 2.X

With Rails >= 3.X (NOT THIS BRANCH!)

Switch to the master branch (releases will be in 4+ range) The 4.x+ versions of this gem require at least Rails 3


From version 3.2.x to version 3.3.x

  1. If you had customized mailer views you might need to update the name. The built-in views have been changed from with a .text:


    to without


From version 3.1.x to version 3.2.x

  1. Update the way CapistranoMailer is configured using the new method: CapMailer.configure (see Usage below).
  2. require the cap mailer config file (see Usage below)

From version 2.1.0 to version 3.1.x:

  1. Update the way CapistranoMailer is configured using the new method: CapMailer.configure_capistrano_mailer (changed in later versions to just 'configure') (see Usage below).
  2. Update the require statement at the top of deploy.rb, see below (note for plugin change from capistrano_mailer to capistrano/mailer).
  3. Change the mailer.send to mailer.send_notification_email in your cap recipe.


1) You need to have already setup capistrano in the project, including the 'capify .' command.

2) Load the Capistrano plugin: Add this line to the top of your config/deploy.rb:

require 'capistrano/mailer'

# configure capistrano_mailer
# The configuration file can go anywhere, but in past versions of the gem it was required to be in the config/ dir.
require 'config/cap_mailer_settings'

3) Configure Capistrano Mailer in the settings file required in step 2 (config/cap_mailer_settings or whatever you called it):

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.sendmail_settings = {
  :location       => '/usr/sbin/sendmail',
  :arguments      => "-i -t -f" # the address your deployment notification emails will come from

CapMailer.configure do |config|
  config[:recipient_addresses]  = [""]
  config[:sender_address]       = ""
  config[:subject_prepend]      = "[EMPTY-CAP-DEPLOY]"
  config[:site_name]            = "Empty App"

4) Setup the tasks.

# load recipes for notification (or roll your own)
require 'capistrano/mailer_recipes'

OR: Roll your own! Add these two tasks to your deploy.rb:

namespace :show do
  task :me do
    set :task_name, task_call_frames.first.task.fully_qualified_name

namespace :deploy do
  desc "Send email notification of deployment"
  task :notify, :roles => :app do  # this sets the task_name variable

    # Set the release notes
    git_commits_range = "#{previous_revision.strip}..#{current_revision.strip}"
    git_log = `git log --pretty=oneline --abbrev-commit #{git_commits_range}` # executes in local shell
    set :release_notes, git_log.blank? ? "No Changes since last deploy." : "from git:\n" + git_log

    # These are overridden by settings from configure the block:
    #   CapMailer.configure do |config|
    #     config[:attach_log_on] = [:failure]
    #   end
    mailer.send_notification_email(self, {
      #:attach_log_on => [:success, :failure],
      :release_notes => release_notes

5) Make sure you've defined rails_env, repository, deploy_to, host, and application. task_name is defined by the show:me task above, and the others are defined behind the scenes by Capistrano!

6) The only parameter to mailer.send_notification_email that is required is the first, and it should always be self. Minimally you need to define the capistrano variables:

:task_name (provided by the show:me task included in this readme)

7) You can set any variable and send it to be rendered as a custom section in the notification email using the third parameter to send_notification_email:

    set :hot_slice_of_wonder, 'This is just so cool'

      self, # will contain everything defined with set, but capistrano mailer will only know to pull some of them for rendering
      { :attach_log_on => [:success, :failure] }, # Custom configurations
      { :my_super_awesome_thing => hot_slice_of_wonder }

8) Then add the hook somewhere in your deploy.rb (if you required capistrano/mailer_recipes this is already done):

after "deploy", "deploy:notify"

9) Enjoy and Happy Capping!


If you want to use your own views you'll need to recreate the notification_email view: First you need to define where your templates are:

CapMailer.configure_capistrano_mailer do |config|
  config[:template_root]      = "app/views/capistrano_mailer/"

Then you'll need to create templates there called:


and / or


Take a look at the templates that comes with the plugin to see how it is done (views/cap_mailer/...)

Credit where Credit is Due

Peter Boling (pboling) - Wrote original & maintainer Dave Nolan (textgoeshere) - lots of refactoring for 3.2 release Jason Rust (jrust) - Updated for Rails 3 compatibility

Thanks to Dustin Deyoung (ddeyoung) for the beautiful HTML email templates. Thanks to mixonix and Yoan Blanc (greut) for work on SCMs compatibility

How you can help!

Take a look at the reek list which is the file called REEK and stat fixing things. Once you complete a change, run the tests:

bundle exec rake test:all

If the tests pass refresh the reek list:

bundle exec rake reek > REEK

Follow the instructions for "Contributing" below.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency 'capistrano_mailer', '~> 0.5'


  • MIT License - See LICENSE file in this project
  • Copyright (c) 2008-2014 Peter H. Boling of Rails Bling
  • Copyright (c) 2007-8 Peter Boling & Sagebit, LLC
Something went wrong with that request. Please try again.