cap_gun 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +81 -0
- data/cap_gun.gemspec +48 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/cap_gun.rb +126 -0
- data/manifest.txt +14 -0
- data/spec/cap_gun_spec.rb +101 -0
- data/tasks/cap_bot_tasks.rake +4 -0
- data/vendor/action_mailer_tls/README +19 -0
- data/vendor/action_mailer_tls/init.rb +1 -0
- data/vendor/action_mailer_tls/lib/smtp_tls.rb +65 -0
- data/vendor/action_mailer_tls/sample/mailer.yml.sample +6 -0
- data/vendor/action_mailer_tls/sample/smtp_gmail.rb +12 -0
- metadata +75 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.0.1. Initial release. Rock n roll mcdonalds.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Relevance, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= CapGun
|
2
|
+
|
3
|
+
== DESCRIPTION
|
4
|
+
|
5
|
+
Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
6
|
+
|
7
|
+
Drop your ActionMailer configuration information into your deploy.rb file, configure recipients for the deployment notifications, and setup the callback task.
|
8
|
+
|
9
|
+
Setup and configuration are done entirely inside your deploy.rb file to KISS. Your emails are sent locally, from the box performing the deployment, but CapGun queries the server to grab the necessary release info.
|
10
|
+
|
11
|
+
We include the Net::SMTP TLS hack inside as a vendored dependancy to allow super easy email sending without setting up an MTA.
|
12
|
+
|
13
|
+
== CONFIG
|
14
|
+
|
15
|
+
In your Capistrano config file (usually deploy.rb):
|
16
|
+
|
17
|
+
# setup action mailer with a hash of options
|
18
|
+
set :cap_gun_action_mailer_config, {
|
19
|
+
:address => "smtp.gmail.com",
|
20
|
+
:port => 587,
|
21
|
+
:user_name => "[YOUR_USERNAME]@gmail.com",
|
22
|
+
:password => "[YOUR_PASSWORD]",
|
23
|
+
:authentication => :plain
|
24
|
+
}
|
25
|
+
|
26
|
+
# define the options for the actual emails that go out -- :recipients is the only required option
|
27
|
+
set :cap_gun_email_envelope, { :recipients => %w[joe@example.com, jane@example.com] }
|
28
|
+
|
29
|
+
# register email as a callback after restart
|
30
|
+
after "deploy:restart", "cap_gun:email"
|
31
|
+
|
32
|
+
# Test everything out by running "cap cap_gun:email"
|
33
|
+
|
34
|
+
== REQUIREMENTS
|
35
|
+
|
36
|
+
* Capistrano 2+
|
37
|
+
* A Gmail account to send from, or an MTA installed locally to send from
|
38
|
+
* Something to deploy
|
39
|
+
|
40
|
+
== TODO & KNOWN ISSUES
|
41
|
+
|
42
|
+
* displays the release times in UTC (Capistrano default) - could be flipped to specified time zone
|
43
|
+
* some stuff will probably break on windows
|
44
|
+
|
45
|
+
== INSTALL
|
46
|
+
|
47
|
+
* sudo gem install cap_gun and gem unpack into your vendor/plugins
|
48
|
+
* or just grab the tarball from github (see below)
|
49
|
+
|
50
|
+
|
51
|
+
== URLS
|
52
|
+
|
53
|
+
* Log bugs, issues, and suggestions on Trac: http://opensource.thinkrelevance.com/wiki/cap_gun
|
54
|
+
* View source: http://github.com/relevance/cap_gun/tree/master
|
55
|
+
* Git clone source: git://github.com/relevance/cap_gun.git
|
56
|
+
* RDocs: http://thinkrelevance.rubyforge.org/cap_gun/
|
57
|
+
|
58
|
+
== LICENSE
|
59
|
+
|
60
|
+
(The MIT License)
|
61
|
+
|
62
|
+
Copyright (c) 2008 Relevance, Inc. - http://thinkrelevance.com
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
65
|
+
a copy of this software and associated documentation files (the
|
66
|
+
'Software'), to deal in the Software without restriction, including
|
67
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
68
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
69
|
+
permit persons to whom the Software is furnished to do so, subject to
|
70
|
+
the following conditions:
|
71
|
+
|
72
|
+
The above copyright notice and this permission notice shall be
|
73
|
+
included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
76
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
77
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
78
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
79
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
80
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
81
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/cap_gun.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Cap_gun-0.0.1
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{cap_gun}
|
7
|
+
s.version = "0.0.1"
|
8
|
+
|
9
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Rob Sanheim, Relevance"]
|
13
|
+
s.date = %q{2008-04-17}
|
14
|
+
s.description = %q{Super simple capistrano deployments.}
|
15
|
+
s.email = %q{opensource@thinkrelevance.com}
|
16
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/cap_gun.rb", "MIT-LICENSE", "README.rdoc"]
|
17
|
+
s.files = ["CHANGELOG", "init.rb", "install.rb", "lib/cap_gun.rb", "manifest.txt", "MIT-LICENSE", "README.rdoc", "spec/cap_gun_spec.rb", "tasks/cap_bot_tasks.rake", "vendor/action_mailer_tls/init.rb", "vendor/action_mailer_tls/lib/smtp_tls.rb", "vendor/action_mailer_tls/README", "vendor/action_mailer_tls/sample/mailer.yml.sample", "vendor/action_mailer_tls/sample/smtp_gmail.rb", "cap_gun.gemspec"]
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.homepage = %q{http://opensource.thinkrelevance.com/wiki/cap_gun}
|
20
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cap_gun", "--main", "README.rdoc"]
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.rubyforge_project = %q{thinkrelevance}
|
23
|
+
s.rubygems_version = %q{1.1.1}
|
24
|
+
s.summary = %q{Bang! You're deployed!}
|
25
|
+
s.test_files = ["spec/cap_gun_spec.rb"]
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# # Original Rakefile source (requires the Echoe gem):
|
30
|
+
#
|
31
|
+
# require 'rubygems'
|
32
|
+
# require 'echoe'
|
33
|
+
# require './lib/cap_gun.rb'
|
34
|
+
#
|
35
|
+
# hoe = Echoe.new('cap_gun') do |p|
|
36
|
+
# p.rubyforge_name = 'thinkrelevance'
|
37
|
+
# p.author = ["Rob Sanheim", "Relevance"]
|
38
|
+
# p.email = 'opensource@thinkrelevance.com'
|
39
|
+
# p.version = CapGun::VERSION
|
40
|
+
# p.summary = "Bang! You're deployed!"
|
41
|
+
# p.description = 'Super simple capistrano deployments.'
|
42
|
+
# p.url = "http://opensource.thinkrelevance.com/wiki/cap_gun"
|
43
|
+
# p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc|CHANGELOG|MIT-LICENSE$/
|
44
|
+
# rdoc_template = `allison --path`.strip << ".rb"
|
45
|
+
# p.rdoc_template = rdoc_template
|
46
|
+
# p.test_pattern = 'spec/**/*_spec.rb'
|
47
|
+
# p.manifest_name = 'manifest.txt'
|
48
|
+
# end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/cap_gun.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'action_mailer'
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. vendor action_mailer_tls lib smtp_tls])
|
4
|
+
|
5
|
+
# Tell everyone about your releases! Send email notification after Capistrano deployments! Rule the world!
|
6
|
+
#
|
7
|
+
# We include the ActionMailer hack to play nice with Gmail, so that's a super easy way
|
8
|
+
# to do this without setting up your own MTA.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# Want to just shoot everyone an email about the latest status?
|
13
|
+
#
|
14
|
+
# cap cap_gun:email
|
15
|
+
#
|
16
|
+
# Include comments?
|
17
|
+
#
|
18
|
+
# cap -s comment="hi mom" cap_gun:email
|
19
|
+
#
|
20
|
+
# Enable emails after every deploy by adding this to your deploy.rb:
|
21
|
+
#
|
22
|
+
# after "deploy", "cap_gun:email"
|
23
|
+
#
|
24
|
+
# Now, next time you deploy, you can optionally include comments:
|
25
|
+
#
|
26
|
+
# cap -s comment="fix for bug #303" deploy
|
27
|
+
#
|
28
|
+
module CapGun
|
29
|
+
VERSION = '0.0.1'
|
30
|
+
|
31
|
+
module Helper
|
32
|
+
|
33
|
+
# Loads ActionMailer settings from a Capistrano variable called "cap_gun_action_mailer_config"
|
34
|
+
def load_mailer_config(cap)
|
35
|
+
raise ArgumentError, "You must define ActionMailer settings in 'cap_gun_action_mailer_config'" unless cap.cap_gun_action_mailer_config
|
36
|
+
raise ArgumentError, "Need at least one recipient." if !cap.exists?(:cap_gun_email_envelope) || cap[:cap_gun_email_envelope][:recipients].blank?
|
37
|
+
|
38
|
+
ActionMailer::Base.smtp_settings = cap.cap_gun_action_mailer_config
|
39
|
+
end
|
40
|
+
|
41
|
+
# Current user - unsupported on Windows
|
42
|
+
def current_user
|
43
|
+
platform.include?('mswin') ? nil : `id -un`.strip
|
44
|
+
end
|
45
|
+
|
46
|
+
# stub hook purposes only
|
47
|
+
def platform
|
48
|
+
RUBY_PLATFORM
|
49
|
+
end
|
50
|
+
|
51
|
+
# Assuming the standard Capistrano timestamp directory, gives you a prettier date/time for output.
|
52
|
+
# This does not take into account anything to do with timezones, but I believe Capistrano always
|
53
|
+
# uses UTC so we could convert to a specified time zone for even friendlier display.
|
54
|
+
def humanize_release_time(path)
|
55
|
+
match = path.match(/(\d+)$/)
|
56
|
+
return unless match
|
57
|
+
time = Time.parse(match[1])
|
58
|
+
time.strftime("%B #{time.day.ordinalize}, %Y %l:%M %p %Z").gsub(/\s+/, ' ').strip
|
59
|
+
end
|
60
|
+
|
61
|
+
extend self
|
62
|
+
end
|
63
|
+
|
64
|
+
# This mailer is configured with a capistrano variable called "cap_gun_email_envelope"
|
65
|
+
class Mailer < ActionMailer::Base
|
66
|
+
include CapGun::Helper
|
67
|
+
DEFAULT_SENDER = %("CapGun" <cap_gun@example.com>)
|
68
|
+
DEFAULT_EMAIL_PREFIX = "[DEPLOY] "
|
69
|
+
|
70
|
+
adv_attr_accessor :email_prefix
|
71
|
+
|
72
|
+
# Grab the options for emaililng from cap_gun_email_envelope (should be set in your deploy file)
|
73
|
+
def init(envelope = {})
|
74
|
+
recipients envelope[:recipients]
|
75
|
+
from (envelope[:from] || DEFAULT_SENDER)
|
76
|
+
email_prefix (envelope[:email_prefix] || DEFAULT_EMAIL_PREFIX)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Do the actual email
|
80
|
+
def deployment_notification(capistrano)
|
81
|
+
init(capistrano[:cap_gun_email_envelope])
|
82
|
+
|
83
|
+
content_type "text/plain"
|
84
|
+
subject "#{email_prefix} #{capistrano[:application]} deployed to #{capistrano[:rails_env]}"
|
85
|
+
body create_body(capistrano)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Create the body of the message using a bunch of values from Capistrano
|
89
|
+
def create_body(capistrano)
|
90
|
+
<<-EOL
|
91
|
+
#{capistrano[:application]} was deployed to #{capistrano[:rails_env]} by #{current_user} at #{humanize_release_time(capistrano[:current_release])}.
|
92
|
+
|
93
|
+
Comment: #{capistrano[:comment] || "[none given]"}
|
94
|
+
|
95
|
+
Nerd details
|
96
|
+
============
|
97
|
+
Release: #{capistrano[:current_release]}
|
98
|
+
Release Time: #{humanize_release_time(capistrano[:current_release])}
|
99
|
+
Release Revision: #{capistrano[:current_revision]}
|
100
|
+
|
101
|
+
Previous Release: #{capistrano[:previous_release]}
|
102
|
+
Previous Release Time: #{humanize_release_time(capistrano[:previous_release])}
|
103
|
+
Previous Release Revision: #{capistrano[:previous_revision]}
|
104
|
+
|
105
|
+
Repository: #{capistrano[:repository]}
|
106
|
+
Deploy path: #{capistrano[:deploy_to]}
|
107
|
+
EOL
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
if Object.const_defined?("Capistrano")
|
114
|
+
|
115
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
116
|
+
|
117
|
+
namespace :cap_gun do
|
118
|
+
desc "Send notification of the current release and the previous release via email."
|
119
|
+
task :email do
|
120
|
+
CapGun::Helper.load_mailer_config(self)
|
121
|
+
CapGun::Mailer.deliver_deployment_notification(self)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
data/manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
init.rb
|
3
|
+
install.rb
|
4
|
+
lib/cap_gun.rb
|
5
|
+
manifest.txt
|
6
|
+
MIT-LICENSE
|
7
|
+
README.rdoc
|
8
|
+
spec/cap_gun_spec.rb
|
9
|
+
tasks/cap_bot_tasks.rake
|
10
|
+
vendor/action_mailer_tls/init.rb
|
11
|
+
vendor/action_mailer_tls/lib/smtp_tls.rb
|
12
|
+
vendor/action_mailer_tls/README
|
13
|
+
vendor/action_mailer_tls/sample/mailer.yml.sample
|
14
|
+
vendor/action_mailer_tls/sample/smtp_gmail.rb
|
@@ -0,0 +1,101 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test/spec'
|
5
|
+
require 'mocha'
|
6
|
+
require 'net/smtp'
|
7
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib cap_gun])
|
8
|
+
|
9
|
+
describe "CapGun" do
|
10
|
+
it "uses action mailer hack" do
|
11
|
+
Net::SMTP.new('').respond_to?(:starttls, true).should == true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "CapGun" do
|
16
|
+
|
17
|
+
describe "mail settings" do
|
18
|
+
include CapGun::Helper
|
19
|
+
|
20
|
+
it "raises if we don't have settings" do
|
21
|
+
capistrano = stub_everything
|
22
|
+
lambda { CapGun::Helper.load_mailer_config(capistrano) }.should.raise(ArgumentError).message.should == "You must define ActionMailer settings in 'cap_gun_action_mailer_config'"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "gets action mailer config from capistrano" do
|
26
|
+
capistrano = stub(:cap_gun_action_mailer_config => {:account => "foo@gmail.com", :password => "password"}, :exists? => true)
|
27
|
+
capistrano.stubs(:[]).returns({:recipients => 'foo'})
|
28
|
+
CapGun::Helper.load_mailer_config(capistrano)
|
29
|
+
ActionMailer::Base.smtp_settings.should == {:account => "foo@gmail.com", :password => "password"}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises if we have no cap gun email envelope" do
|
33
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :exists? => false)
|
34
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises if we don't have at least one recipient" do
|
38
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {})
|
39
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
40
|
+
capistrano = stub_everything(:cap_gun_action_mailer_config => {}, :cap_gun_email_envelope => {:recipients => []})
|
41
|
+
lambda { CapGun::Helper.load_mailer_config capistrano }.should.raise(ArgumentError)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "misc helpers" do
|
47
|
+
include CapGun::Helper
|
48
|
+
|
49
|
+
it "returns nil for current user if platform is win32" do
|
50
|
+
expects(:platform).returns("mswin")
|
51
|
+
current_user.should.be nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should get current user from *nix id command" do
|
55
|
+
expects(:"`").with('id -un').returns("joe")
|
56
|
+
current_user
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns nil for weird release path" do
|
60
|
+
humanize_release_time("/data/foo/my_release").should == nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "parse datetime from release path" do
|
64
|
+
humanize_release_time("/data/foo/releases/20080402152141").should == "April 2nd, 2008 3:21 PM EDT"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "Mailer" do
|
70
|
+
|
71
|
+
it "passes capistrano into create body" do
|
72
|
+
capistrano = { :current_release => "/data/foo", :previous_release => "/data/foo", :cap_gun_email_envelope => {:recipients => ["joe@example.com"]} }
|
73
|
+
CapGun::Mailer.any_instance.expects(:create_body).with(capistrano).returns("foo")
|
74
|
+
CapGun::Mailer.create_deployment_notification capistrano
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "Mail envelope" do
|
80
|
+
before { CapGun::Mailer.any_instance.stubs(:create_body).returns("email body!") }
|
81
|
+
|
82
|
+
it "gets recipients from email envelope" do
|
83
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => ["foo@here.com", "bar@here.com"] } }
|
84
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
85
|
+
mail.to.should == ["foo@here.com", "bar@here.com"]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should have a default sender" do
|
89
|
+
capistrano = { :cap_gun_email_envelope => { :recipients => "foo@here.com" } }
|
90
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
91
|
+
mail.from.should == ["cap_gun@example.com"]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should override sender from email envelope" do
|
95
|
+
capistrano = { :cap_gun_email_envelope => { :from => "booyakka!@example.com", :recipients => ["foo@here.com", "bar@here.com"] } }
|
96
|
+
mail = CapGun::Mailer.create_deployment_notification capistrano
|
97
|
+
mail.from.should == ["booyakka!@example.com"]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= SMTP_TLS + ActionMailer + Gmail
|
2
|
+
|
3
|
+
Configure Rails To Use Gmail's SMTP
|
4
|
+
|
5
|
+
Originally from http://blog.pomozov.info/posts/how-to-send-actionmailer-mails-to-gmailcom.html
|
6
|
+
|
7
|
+
See "sample" directory for further instructions
|
8
|
+
|
9
|
+
== Resources
|
10
|
+
|
11
|
+
Blog post
|
12
|
+
|
13
|
+
* http://www.rubyinside.com/how-to-use-gmails-smtp-server-with-rails-394.html
|
14
|
+
|
15
|
+
* http://www.prestonlee.com/archives/63
|
16
|
+
|
17
|
+
== Author
|
18
|
+
|
19
|
+
* Marc Chung - marc [dot] chung [at] openrain [dot] com
|
@@ -0,0 +1 @@
|
|
1
|
+
require_dependency 'smtp_tls'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "net/smtp"
|
3
|
+
|
4
|
+
Net::SMTP.class_eval do
|
5
|
+
private
|
6
|
+
def do_start(helodomain, user, secret, authtype)
|
7
|
+
raise IOError, 'SMTP session already started' if @started
|
8
|
+
check_auth_args user, secret, authtype if user or secret
|
9
|
+
|
10
|
+
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
11
|
+
@socket = Net::InternetMessageIO.new(sock)
|
12
|
+
@socket.read_timeout = 60 #@read_timeout
|
13
|
+
|
14
|
+
check_response(critical { recv_response() })
|
15
|
+
do_helo(helodomain)
|
16
|
+
|
17
|
+
if starttls
|
18
|
+
raise 'openssl library not installed' unless defined?(OpenSSL)
|
19
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
|
20
|
+
ssl.sync_close = true
|
21
|
+
ssl.connect
|
22
|
+
@socket = Net::InternetMessageIO.new(ssl)
|
23
|
+
@socket.read_timeout = 60 #@read_timeout
|
24
|
+
do_helo(helodomain)
|
25
|
+
end
|
26
|
+
|
27
|
+
authenticate user, secret, authtype if user
|
28
|
+
@started = true
|
29
|
+
ensure
|
30
|
+
unless @started
|
31
|
+
# authentication failed, cancel connection.
|
32
|
+
@socket.close if not @started and @socket and not @socket.closed?
|
33
|
+
@socket = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_helo(helodomain)
|
38
|
+
begin
|
39
|
+
if @esmtp
|
40
|
+
ehlo helodomain
|
41
|
+
else
|
42
|
+
helo helodomain
|
43
|
+
end
|
44
|
+
rescue Net::ProtocolError
|
45
|
+
if @esmtp
|
46
|
+
@esmtp = false
|
47
|
+
@error_occured = false
|
48
|
+
retry
|
49
|
+
end
|
50
|
+
raise
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def starttls
|
55
|
+
getok('STARTTLS') rescue return false
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
|
59
|
+
def quit
|
60
|
+
begin
|
61
|
+
getok('QUIT')
|
62
|
+
rescue EOFError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#
|
2
|
+
# For Rails 2.x:
|
3
|
+
# A copy of this file should be placed in RAILS_ROOT/initializers/
|
4
|
+
# A file named mailer.yml should be placed in RAILS_ROOT/config/
|
5
|
+
# See mailer.yml.sample
|
6
|
+
#
|
7
|
+
|
8
|
+
require "smtp_tls"
|
9
|
+
|
10
|
+
mailer_config = File.open("#{RAILS_ROOT}/config/mailer.yml")
|
11
|
+
mailer_options = YAML.load(mailer_config)
|
12
|
+
ActionMailer::Base.smtp_settings = mailer_options
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap_gun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Sanheim, Relevance
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-04-17 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Super simple capistrano deployments.
|
17
|
+
email: opensource@thinkrelevance.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/cap_gun.rb
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- init.rb
|
30
|
+
- install.rb
|
31
|
+
- lib/cap_gun.rb
|
32
|
+
- manifest.txt
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- spec/cap_gun_spec.rb
|
36
|
+
- tasks/cap_bot_tasks.rake
|
37
|
+
- vendor/action_mailer_tls/init.rb
|
38
|
+
- vendor/action_mailer_tls/lib/smtp_tls.rb
|
39
|
+
- vendor/action_mailer_tls/README
|
40
|
+
- vendor/action_mailer_tls/sample/mailer.yml.sample
|
41
|
+
- vendor/action_mailer_tls/sample/smtp_gmail.rb
|
42
|
+
- cap_gun.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://opensource.thinkrelevance.com/wiki/cap_gun
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --line-numbers
|
48
|
+
- --inline-source
|
49
|
+
- --title
|
50
|
+
- Cap_gun
|
51
|
+
- --main
|
52
|
+
- README.rdoc
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: thinkrelevance
|
70
|
+
rubygems_version: 1.1.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: Bang! You're deployed!
|
74
|
+
test_files:
|
75
|
+
- spec/cap_gun_spec.rb
|