openrain-action_mailer_tls 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ == 1.1.0 / 2009-02-10
2
+ * Converted plugin into a Rubygem with a Rails generator.
3
+ * Updated README with installation details.
4
+
5
+ == 1.0.0 / 2009-02-09
6
+ * Tagging original SVN migration.
data/README.markdown ADDED
@@ -0,0 +1,82 @@
1
+ ActionMailerTLS
2
+ ===============
3
+
4
+ Background
5
+ ----------
6
+
7
+ This Ruby on Rails plugin makes it trivial to send email through a Google Apps for business account.
8
+
9
+ This gem will only work on Ruby 1.8.6.
10
+
11
+ Installation
12
+ ------------
13
+
14
+ If you're on Ruby 1.8.7 and Rails >= 2.2.1, you don't need this plugin. See Notes below.
15
+
16
+ To install the gem (the preferred way):
17
+
18
+ 1. sudo gem install openrain-action_mailer_tls -s http://gems.github.com
19
+ 2. ./script/generate action_mailer_tls
20
+ 3. Copy RAILS_ROOT/config/smtp_gmail.yml.sample to RAILS_ROOT/config/smtp_gmail.yml
21
+ 4. Update the configuration file with your settings
22
+
23
+ To (optionally) vendor this gem
24
+ 1. Add config.gem "openrain-action_mailer_tls", :source => "http://gems.github.com"
25
+ 2. rake gems:unpack
26
+
27
+ To install the plugin (the old way)
28
+
29
+ 1. ./script/plugin install git://github.com/openrain/action_mailer_tls.git -r '1.0.0'
30
+ 2. Copy vendor/plugins/action_mailer_tls/sample/smtp_gmail.rb to config/
31
+ 3. Copy vendor/plugins/action_mailer_tls/sample/mailer.yml.sample to config/
32
+ 4. Update the configuration file with your settings
33
+
34
+ Testing it out
35
+ --------------
36
+
37
+ 1. ./script/generate mailer Notifier hello_world
38
+ 2. Add the following lines to config/environments/development.rb
39
+ config.action_mailer.raise_delivery_errors = true
40
+ config.action_mailer.perform_deliveries = true
41
+ config.action_mailer.delivery_method = :smtp
42
+ 3. Update the recipients and from fields in app/models/notifier.rb
43
+ 4. ./script/console
44
+ 5. >> Notifier.deliver_hello_world!
45
+
46
+ Resources
47
+ ---------
48
+
49
+ Blog posts
50
+
51
+ * http://www.rubyinside.com/how-to-use-gmails-smtp-server-with-rails-394.html
52
+ * http://www.prestonlee.com/archives/63
53
+
54
+ Books
55
+
56
+ * Advanced Rails Recipes pg. 238, Recipe #47.
57
+
58
+ Notes
59
+ -----
60
+
61
+ If you're running Rails >= 2.2.1 [RC2] and Ruby 1.8.7, you don't need this plugin. Ruby 1.8.7 supports
62
+ SMTP TLS and Rails 2.2.1 ships with an option to enable it if you're running Ruby 1.8.7.
63
+
64
+ To set it all up, in config/initializers/smtp_gmail.rb:
65
+ ActionMailer::Base.smtp_settings = {
66
+ :address => "smtp.gmail.com",
67
+ :port => 587,
68
+ :authentication => :plain,
69
+ :enable_starttls_auto => true
70
+ :user_name: your_username@gmail.com
71
+ :password: h@ckme
72
+ }
73
+
74
+ http://github.com/rails/rails/commit/732c724df61bc8b780dc42817625b25a321908e4
75
+
76
+ Author
77
+ ------
78
+ * Marc Chung - marc [dot] chung [at] openrain [dot] com
79
+
80
+ License
81
+ -------
82
+ * Copyright (c) 2009 OpenRain, LLC. See MIT-LICENSE for details
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 1
4
+ :minor: 1
data/generators/USAGE ADDED
@@ -0,0 +1,16 @@
1
+ Description:
2
+ The action_mailer_tls generator adds smtp-tls support to your Rails projects.
3
+
4
+ The generator takes no arguments and only needs to be run once. It will create
5
+ a Rails initializer for Gmail, and a sample YAML configuration file.
6
+
7
+ Modify the contents of the configuration file with your Gmail username and
8
+ password
9
+
10
+ Example:
11
+ ./script/generate action_mailer_tls
12
+
13
+ This will create the following files:
14
+ Initializer: config/initializers/smtp_gmail.rb
15
+ Config: config/smtp_gmail.yml.sample
16
+
@@ -0,0 +1,11 @@
1
+ # This generator intalls ActionMailerTLS into a Rails project
2
+ class ActionMailerTlsGenerator < Rails::Generator::Base
3
+
4
+ def manifest
5
+ record do |m|
6
+ m.file "config/smtp_gmail.yml.sample", "config/smtp_gmail.yml.sample"
7
+ m.file "config/initializers/smtp_gmail.rb", "config/initializers/smtp_gmail.rb"
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,14 @@
1
+ # This file is automatically copied into RAILS_ROOT/initializers
2
+
3
+ require "smtp_tls"
4
+
5
+ config_file = "#{RAILS_ROOT}/config/smtp_gmail.yml"
6
+ raise "Sorry, you must have #{config_file}" unless File.exists?(config_file)
7
+
8
+ config_options = YAML.load_file(config_file)
9
+ ActionMailer::Base.smtp_settings = {
10
+ :address => "smtp.gmail.com",
11
+ :port => 587,
12
+ :authentication => :plain,
13
+ :enable_starttls_auto => true
14
+ }.merge(config_options) # Configuration options override default options
@@ -0,0 +1,3 @@
1
+ ---
2
+ :user_name: your_username@gmail.com
3
+ :password: h@ckme
data/lib/smtp_tls.rb ADDED
@@ -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
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openrain-action_mailer_tls
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marc Chung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-10 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Conveniently send emails through Google's Hosted App service
17
+ email: marc.chung@openrain.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - History.txt
26
+ - README.markdown
27
+ - VERSION.yml
28
+ - generators/USAGE
29
+ - generators/action_mailer_tls_generator.rb
30
+ - generators/templates
31
+ - generators/templates/config
32
+ - generators/templates/config/initializers
33
+ - generators/templates/config/initializers/smtp_gmail.rb
34
+ - generators/templates/config/smtp_gmail.yml.sample
35
+ - lib/smtp_tls.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/openrain/action_mailer_tls
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --inline-source
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Send Email via Gmail
63
+ test_files: []
64
+