Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

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