super_smtp 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in super_smtp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Spiegel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # SuperSmtp
2
+
3
+ Support Specific Source IP in Net::SMTP
4
+
5
+ ## About
6
+
7
+ This is kind of a dumb monkey-patch of Net::SMTP, but it's an easy way to
8
+ support an extra option in Net::SMTP.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'super_smtp'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install super_smtp
23
+
24
+ ## Usage
25
+
26
+ To use, just add a third parameter when you initialize your Net::SMTP connection:
27
+
28
+ ```ruby
29
+ # If my local interface is 192.168.0.2
30
+ smtp = Net::SMTP.new('remote-mx.domain.com', 25, '192.168.0.2')
31
+ # boom. That's it. Simplest gem evar.
32
+ ```
33
+
34
+ ## TODO
35
+
36
+ I dunno... Maybe submit a pull request to Ruby to support this?
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/super_smtp.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'net/smtp'
2
+
3
+ module Net
4
+ class SMTP
5
+ #
6
+ # Creates a new Net::SMTP object.
7
+ #
8
+ # +address+ is the hostname or ip address of your SMTP
9
+ # server. +port+ is the port to connect to; it defaults to
10
+ # port 25.
11
+ #
12
+ # This method does not open the TCP connection. You can use
13
+ # SMTP.start instead of SMTP.new if you want to do everything
14
+ # at once. Otherwise, follow SMTP.new with SMTP#start.
15
+ #
16
+ def initialize(address, port = nil, source_address = nil)
17
+ @address = address
18
+ @source_address = source_address
19
+ @port = (port || SMTP.default_port)
20
+ @esmtp = true
21
+ @capabilities = nil
22
+ @socket = nil
23
+ @started = false
24
+ @open_timeout = 30
25
+ @read_timeout = 60
26
+ @error_occured = false
27
+ @debug_output = nil
28
+ @tls = false
29
+ @starttls = false
30
+ @ssl_context = nil
31
+ end
32
+
33
+ private
34
+
35
+ def tcp_socket(address, port, source_address = nil)
36
+ TCPSocket.open address, port, source_address
37
+ end
38
+
39
+ def do_start(helo_domain, user, secret, authtype)
40
+ raise IOError, 'SMTP session already started' if @started
41
+ if user or secret
42
+ check_auth_method(authtype || DEFAULT_AUTH_TYPE)
43
+ check_auth_args user, secret
44
+ end
45
+ s = timeout(@open_timeout) { tcp_socket(@address, @port, @source_address) }
46
+ logging "Connection opened: #{@address}:#{@port}"
47
+ @socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
48
+ check_response critical { recv_response() }
49
+ do_helo helo_domain
50
+ if starttls_always? or (capable_starttls? and starttls_auto?)
51
+ unless capable_starttls?
52
+ raise SMTPUnsupportedCommand,
53
+ "STARTTLS is not supported on this server"
54
+ end
55
+ starttls
56
+ @socket = new_internet_message_io(tlsconnect(s))
57
+ # helo response may be different after STARTTLS
58
+ do_helo helo_domain
59
+ end
60
+ authenticate user, secret, (authtype || DEFAULT_AUTH_TYPE) if user
61
+ @started = true
62
+ ensure
63
+ unless @started
64
+ # authentication failed, cancel connection.
65
+ s.close if s and not s.closed?
66
+ @socket = nil
67
+ end
68
+ end
69
+
70
+ end # class SMTP
71
+ end
@@ -0,0 +1,3 @@
1
+ module SuperSmtp
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'super_smtp/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "super_smtp"
8
+ gem.version = SuperSmtp::VERSION
9
+ gem.authors = ["Aaron Spiegel"]
10
+ gem.email = ["spiegela@gmail.com"]
11
+ gem.description = %q{Support Specific Source IP in Net::SMTP}
12
+ gem.summary = gem.description
13
+ gem.homepage = "http://www.github.com/spiegela/super_smtp"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: super_smtp
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Spiegel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Support Specific Source IP in Net::SMTP
15
+ email:
16
+ - spiegela@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/super_smtp.rb
27
+ - lib/super_smtp/version.rb
28
+ - super_smtp.gemspec
29
+ homepage: http://www.github.com/spiegela/super_smtp
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Support Specific Source IP in Net::SMTP
53
+ test_files: []
54
+ has_rdoc: