net-smtp-proxy 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b21b652bd81a297ede1bf7d17f5d0cf905defc5c371ede6c9f43e0480e8118f
4
- data.tar.gz: 861663272537d7d5ef072dec5d593235424d7ebbe6d96e042a4d435797a7acfe
3
+ metadata.gz: e461f6f7c17acc5fb3fcd5a9bd3fa830be74d491a5b32da3a4edd2fe51ab6187
4
+ data.tar.gz: 79ac2ee20166f4b23f5676f40b6045bb38cf4e82a1a593903efc592b874a7050
5
5
  SHA512:
6
- metadata.gz: b53016b660aa90d84f020b2c44920124a467e84016f4cc5eb82d223c4c638724573e3420b61a8125241b74cd4fac6a20d01a0fd80cb6c1336a05e9c5abfad06a
7
- data.tar.gz: 1fe4d577140248f324305d3e21665059c54a8b50722b8275c2a4a3e49c320f178aa15daf96dcf8bdcb81e01aa6554c496f1197b67a1857ba6950950d4f50ddd9
6
+ metadata.gz: ca662340ca87f6d80b99f130d5c87c96f7dcfccbdf4d598a5859379e536b19bf6a5d36f78bb517f1f6e6b4820e4ee58cf95b9a023c99986a3c7b2ef853a57fd6
7
+ data.tar.gz: 462268f69e3910707ae18cd4445364dd68fb608238c9224527e45c6513c6345d5c20982a838bbf1f4057d00fad5f4b184b55fb26c5601d7337b7ac8f5e44b7f8
@@ -0,0 +1,76 @@
1
+ ## net-smtp-proxy
2
+ Proxy support for Ruby's Net::SMTP library.
3
+
4
+ ## Installation
5
+
6
+ `gem install net-smtp-proxy`
7
+
8
+ or put it in your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'net-smtp-proxy'
12
+ ```
13
+
14
+ Once it's available in your project, require it like so:
15
+
16
+ ```ruby
17
+ require 'net/smtp/proxy'
18
+ ```
19
+
20
+ ### What is this Thing?
21
+
22
+ This gem allows you to connect to an SMTP server by way of an HTTP proxy. Why would you want to do that? I'm sure a number of use-cases exist, but I specifically needed to connect to the Gmail SMTP relay service in order to send an email from a company-wide alias. Normally, Gmail requires you to provide the credentials for the sender's account when sending an email. The relay service however replaces the usual password authentication with IP whitelisting. You provide Google with a static IP address that all your SMTP requests will come from. The SMTP relay service also allows you to send email from company-wide email aliases, i.e. accounts that don't have a login. In our case, we wanted to send an email from the Platform Engineering Team as opposed to one specific member of that team. We already had [Squid](http://www.squid-cache.org/) set up as a [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) with a static IP, so we whitelisted the IP with Google and wrote this gem to send SMTP requests through the proxy.
23
+
24
+ ### Usage
25
+
26
+ Instantiate an instance of the `Proxy` class and use it to make SMTP requests:
27
+
28
+ ```ruby
29
+ address = 'smtp-relay.gmail.com'
30
+ port = 587
31
+ proxy_address = 'http://myproxy.mydomain.com'
32
+ proxy_port = 1234
33
+
34
+ proxy = Net::SMTP::Proxy.new(address, port, proxy_address, proxy_port)
35
+
36
+ proxy.start do |smtp|
37
+ smtp.helo('mydomain.com')
38
+ end
39
+ ```
40
+
41
+ You can also use the `.start` method to accomplish the same thing:
42
+
43
+ ```ruby
44
+ Net::SMTP::Proxy.start(address, port, proxy_address, proxy_port) do |smtp|
45
+ smtp.helo('mydomain.com')
46
+ end
47
+ ```
48
+
49
+ ### Integration with the Mail Gem
50
+
51
+ The `DeliveryMethod` class provides an easy way to integrate with the [Mail gem](https://github.com/mikel/mail). Simply pass the class in as the delivery method, providing the same options hash you would pass to the SMTP delivery method (plus the proxy options):
52
+
53
+ ```ruby
54
+ Mail.deliver do
55
+ delivery_method Net::SMTP::Proxy::DeliveryMethod, {
56
+ address: address,
57
+ port: port,
58
+ proxy_address: proxy_address,
59
+ proxy_port: proxy_port,
60
+ domain: 'mydomain.com'
61
+ }
62
+
63
+ from 'from@mydomain.com'
64
+ to 'to@mydomain.com'
65
+ subject 'Mail is cool'
66
+ body "Look ma, I'm sending email!"
67
+ end
68
+ ```
69
+
70
+ ## License
71
+
72
+ Licensed under the MIT license. See LICENSE for details.
73
+
74
+ ## Authors
75
+
76
+ * Cameron C. Dutro: http://github.com/camertron
@@ -2,10 +2,19 @@ require 'net/smtp'
2
2
  require 'proxifier'
3
3
 
4
4
  module Net
5
- module SMTPProxy
5
+ class SMTP
6
6
  class Proxy < SMTP
7
+ autoload :DeliveryMethod, 'net/smtp/proxy/delivery_method'
8
+
7
9
  attr_reader :proxy_address, :proxy_port
8
10
 
11
+ class << self
12
+ def start(address, port = nil, proxy_address = nil, proxy_port = nil,
13
+ helo = 'localhost', user = nil, secret = nil, authtype = nil, &block)
14
+ new(address, port, proxy_address, proxy_port).start(helo, user, secret, authtype, &block)
15
+ end
16
+ end
17
+
9
18
  def initialize(address, port, proxy_address, proxy_port)
10
19
  super(address, port)
11
20
  @proxy_address = proxy_address
@@ -0,0 +1,46 @@
1
+ require 'net/smtp'
2
+
3
+ begin
4
+ require 'mail'
5
+ rescue LoadError
6
+ puts 'The mail gem is required to use the DeliveryMethod class.'
7
+ end
8
+
9
+ module Net
10
+ class SMTP
11
+ class Proxy < SMTP
12
+ # for use with the mail gem
13
+ class DeliveryMethod < ::Mail::SMTP
14
+ private
15
+
16
+ # adapted from
17
+ # https://github.com/mikel/mail/blob/6bc16b4bce4fe280b19523c939b14a30e32a8ba4/lib/mail/network/delivery_methods/smtp.rb#L112
18
+ def build_smtp_session
19
+ init_params = [
20
+ settings[:address], settings[:port],
21
+ settings[:proxy_address], settings[:proxy_port]
22
+ ]
23
+
24
+ Net::SMTP::Proxy.new(*init_params).tap do |smtp|
25
+ if settings[:tls] || settings[:ssl]
26
+ if smtp.respond_to?(:enable_tls)
27
+ smtp.enable_tls(ssl_context)
28
+ end
29
+ elsif settings[:enable_starttls]
30
+ if smtp.respond_to?(:enable_starttls)
31
+ smtp.enable_starttls(ssl_context)
32
+ end
33
+ elsif settings[:enable_starttls_auto]
34
+ if smtp.respond_to?(:enable_starttls_auto)
35
+ smtp.enable_starttls_auto(ssl_context)
36
+ end
37
+ end
38
+
39
+ smtp.open_timeout = settings[:open_timeout] if settings[:open_timeout]
40
+ smtp.read_timeout = settings[:read_timeout] if settings[:read_timeout]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ require 'net/smtp'
2
+
3
+ module Net
4
+ class SMTP
5
+ class Proxy < SMTP
6
+ VERSION = '2.0.0'
7
+ end
8
+ end
9
+ end
@@ -1,14 +1,14 @@
1
1
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
2
- require 'net/smtp-proxy/version'
2
+ require 'net/smtp/proxy/version'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'net-smtp-proxy'
6
- s.version = ::Net::SMTPProxy::VERSION
6
+ s.version = ::Net::SMTP::Proxy::VERSION
7
7
  s.authors = ['Cameron Dutro']
8
8
  s.email = ['camertron@gmail.com']
9
9
  s.homepage = 'http://github.com/camertron'
10
10
 
11
- s.description = s.summary = "Proxy support for Ruby's Net::SMTP."
11
+ s.description = s.summary = "Proxy support for Ruby's Net::SMTP library."
12
12
 
13
13
  s.platform = Gem::Platform::RUBY
14
14
  s.has_rdoc = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-smtp-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2018-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: proxifier
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.5'
55
- description: Proxy support for Ruby's Net::SMTP.
55
+ description: Proxy support for Ruby's Net::SMTP library.
56
56
  email:
57
57
  - camertron@gmail.com
58
58
  executables: []
@@ -60,11 +60,11 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - Gemfile
63
+ - README.md
63
64
  - Rakefile
64
- - lib/net/smtp-proxy.rb
65
- - lib/net/smtp-proxy/delivery_method.rb
66
- - lib/net/smtp-proxy/proxy.rb
67
- - lib/net/smtp-proxy/version.rb
65
+ - lib/net/smtp/proxy.rb
66
+ - lib/net/smtp/proxy/delivery_method.rb
67
+ - lib/net/smtp/proxy/version.rb
68
68
  - net-smtp-proxy.gemspec
69
69
  homepage: http://github.com/camertron
70
70
  licenses: []
@@ -88,5 +88,5 @@ rubyforge_project:
88
88
  rubygems_version: 2.7.6
89
89
  signing_key:
90
90
  specification_version: 4
91
- summary: Proxy support for Ruby's Net::SMTP.
91
+ summary: Proxy support for Ruby's Net::SMTP library.
92
92
  test_files: []
@@ -1,9 +0,0 @@
1
- require 'net/smtp'
2
- require 'proxifier'
3
-
4
- module Net
5
- module SMTPProxy
6
- autoload :DeliveryMethod, 'net/smtp-proxy/delivery_method'
7
- autoload :Proxy, 'net/smtp-proxy/proxy'
8
- end
9
- end
@@ -1,42 +0,0 @@
1
- begin
2
- require 'mail'
3
- rescue LoadError
4
- puts 'The mail gem is required to use the DeliveryMethod class.'
5
- end
6
-
7
- module Net
8
- module SMTPProxy
9
- # for use with the mail gem
10
- class DeliveryMethod < ::Mail::SMTP
11
- private
12
-
13
- # adapted from
14
- # https://github.com/mikel/mail/blob/6bc16b4bce4fe280b19523c939b14a30e32a8ba4/lib/mail/network/delivery_methods/smtp.rb#L112
15
- def build_smtp_session
16
- init_params = [
17
- settings[:address], settings[:port],
18
- settings[:proxy_address], settings[:proxy_port]
19
- ]
20
-
21
- Net::SMTPProxy::Proxy.new(*init_params).tap do |smtp|
22
- if settings[:tls] || settings[:ssl]
23
- if smtp.respond_to?(:enable_tls)
24
- smtp.enable_tls(ssl_context)
25
- end
26
- elsif settings[:enable_starttls]
27
- if smtp.respond_to?(:enable_starttls)
28
- smtp.enable_starttls(ssl_context)
29
- end
30
- elsif settings[:enable_starttls_auto]
31
- if smtp.respond_to?(:enable_starttls_auto)
32
- smtp.enable_starttls_auto(ssl_context)
33
- end
34
- end
35
-
36
- smtp.open_timeout = settings[:open_timeout] if settings[:open_timeout]
37
- smtp.read_timeout = settings[:read_timeout] if settings[:read_timeout]
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,5 +0,0 @@
1
- module Net
2
- module SMTPProxy
3
- VERSION = '1.0.0'
4
- end
5
- end