public
Last active — forked from rtekie/cap_notify.rb

Capistrano deployment email notifier for Rails 3

  • Download Gist
cap_notify.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
=begin
Capistrano deployment email notifier for Rails 3
 
Do you need to send email notifications after application deployments?
 
Christopher Sexton developed a Simple Capistrano email notifier for rails. You can find details at http://www.codeography.com/2010/03/24/simple-capistrano-email-notifier-for-rails.html.
 
Here is Rails 3 port of the notifier.
 
The notifier sends an email after application deployment has been completed.
 
How to use it?
 
1. Add this file to config/deploy folder.
2. Update the file with your google credentials and from email address.
3. Add the following content to config/deploy.rb.
 
require 'config/deploy/cap_notify.rb'
 
# add email addresses for people who should receive deployment notifications
set :notify_emails, ["EMAIL1@YOURDOMAIN.COM", "EMAIL2@YOURDOMAIN.COM"]
 
after :deploy, 'deploy:send_notification'
 
# Create task to send a notification
namespace :deploy do
desc "Send email notification"
task :send_notification do
Notifier.deploy_notification(self).deliver
end
end
 
4. Update deploy.rb with destination email addresses for the notifications.
5. To test run this command:
cap deploy:send_notification
 
=end
 
require "action_mailer"
 
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => "plain",
:user_name => "YOUR USER NAME",
:password => "YOUR PASSWORD"
}
 
class Notifier < ActionMailer::Base
default :from => "YOUR FROM EMAIL"
def deploy_notification(cap_vars)
now = Time.now
msg = "Performed a deploy operation on #{now.strftime("%m/%d/%Y")} at #{now.strftime("%I:%M %p")} to #{cap_vars.host}"
mail(:to => cap_vars.notify_emails,
:subject => "Deployed #{cap_vars.application} to #{cap_vars.stage}") do |format|
format.text { render :text => msg}
format.html { render :text => "<p>" + msg + "<\p>"}
end
end
end

Note to include the gem tlsmail so this works with any mail over ssl.

I had to use load instead of require here because of

   rubygems/custom_require.rb:55:in `require': cannot load such file -- config/deploy/cap_notify.rb (LoadError)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.