net-smtp 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/net/smtp.rb +58 -35
- data/net-smtp.gemspec +7 -5
- metadata +32 -12
- data/.github/workflows/test.yml +0 -24
- data/.gitignore +0 -9
- data/Gemfile +0 -9
- data/NEWS.md +0 -44
- data/README.md +0 -97
- data/Rakefile +0 -10
- data/bin/console +0 -7
- data/bin/setup +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd4c86f571640cbc5441b71f2b0bb89d9cf2b39be60e539dac54b9fc040c7343
|
4
|
+
data.tar.gz: dbe764b541202fe9c38437ca405eb910ba56b2909424ab37fa5d5cb82b719b50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd4c00192ae2ea98feb77d2426f41a9ca1b408350b74d3f937f02dea06ae9bf4d00f6d37cbebcf6e379f0cb9c8fcb0d03125ecc488f4cb74286deba1e40fa9c9
|
7
|
+
data.tar.gz: ffc30083a8984d0dd10351e06acca9dd491846d6cc5e3310b5dfb30d436569da7dc26fa2f253a55789bb0feb2484542be37f448fd51d3c7c66105213c7159666
|
data/lib/net/smtp.rb
CHANGED
@@ -31,6 +31,17 @@ module Net
|
|
31
31
|
module SMTPError
|
32
32
|
# This *class* is a module for backward compatibility.
|
33
33
|
# In later release, this module becomes a class.
|
34
|
+
|
35
|
+
attr_reader :response
|
36
|
+
|
37
|
+
def initialize(response, message: nil)
|
38
|
+
@response = response
|
39
|
+
@message = message
|
40
|
+
end
|
41
|
+
|
42
|
+
def message
|
43
|
+
@message || response.message
|
44
|
+
end
|
34
45
|
end
|
35
46
|
|
36
47
|
# Represents an SMTP authentication error.
|
@@ -168,7 +179,7 @@ module Net
|
|
168
179
|
# user: 'Your Account', secret: 'Your Password', authtype: :cram_md5)
|
169
180
|
#
|
170
181
|
class SMTP < Protocol
|
171
|
-
VERSION = "0.2.
|
182
|
+
VERSION = "0.2.2"
|
172
183
|
|
173
184
|
Revision = %q$Revision$.split[1]
|
174
185
|
|
@@ -191,12 +202,9 @@ module Net
|
|
191
202
|
alias default_ssl_port default_tls_port
|
192
203
|
end
|
193
204
|
|
194
|
-
def SMTP.default_ssl_context(
|
205
|
+
def SMTP.default_ssl_context(ssl_context_params = nil)
|
195
206
|
context = OpenSSL::SSL::SSLContext.new
|
196
|
-
context.
|
197
|
-
store = OpenSSL::X509::Store.new
|
198
|
-
store.set_default_paths
|
199
|
-
context.cert_store = store
|
207
|
+
context.set_params(ssl_context_params ? ssl_context_params : {})
|
200
208
|
context
|
201
209
|
end
|
202
210
|
|
@@ -301,7 +309,7 @@ module Net
|
|
301
309
|
# this object. Must be called before the connection is established
|
302
310
|
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
|
303
311
|
def enable_tls(context = nil)
|
304
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
312
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
305
313
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @starttls == :always
|
306
314
|
@tls = true
|
307
315
|
@ssl_context_tls = context
|
@@ -338,7 +346,7 @@ module Net
|
|
338
346
|
# Enables SMTP/TLS (STARTTLS) for this object.
|
339
347
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
340
348
|
def enable_starttls(context = nil)
|
341
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
349
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
342
350
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
343
351
|
@starttls = :always
|
344
352
|
@ssl_context_starttls = context
|
@@ -347,7 +355,7 @@ module Net
|
|
347
355
|
# Enables SMTP/TLS (STARTTLS) for this object if server accepts.
|
348
356
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
349
357
|
def enable_starttls_auto(context = nil)
|
350
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
358
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
351
359
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
352
360
|
@starttls = :auto
|
353
361
|
@ssl_context_starttls = context
|
@@ -409,14 +417,14 @@ module Net
|
|
409
417
|
|
410
418
|
#
|
411
419
|
# :call-seq:
|
412
|
-
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil) { |smtp| ... }
|
420
|
+
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
|
413
421
|
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
414
422
|
#
|
415
423
|
# Creates a new Net::SMTP object and connects to the server.
|
416
424
|
#
|
417
425
|
# This method is equivalent to:
|
418
426
|
#
|
419
|
-
# Net::SMTP.new(address, port).start(helo: helo_domain, user: account, secret: password, authtype: authtype, tls_verify: flag, tls_hostname: hostname)
|
427
|
+
# Net::SMTP.new(address, port).start(helo: helo_domain, user: account, secret: password, authtype: authtype, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
|
420
428
|
#
|
421
429
|
# === Example
|
422
430
|
#
|
@@ -450,6 +458,11 @@ module Net
|
|
450
458
|
# If the hostname in the server certificate is different from +address+,
|
451
459
|
# it can be specified with +tls_hostname+.
|
452
460
|
#
|
461
|
+
# Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
|
462
|
+
# +OpenSSL::SSL::SSLContext#set_params+
|
463
|
+
#
|
464
|
+
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
465
|
+
#
|
453
466
|
# === Errors
|
454
467
|
#
|
455
468
|
# This method may raise:
|
@@ -465,14 +478,14 @@ module Net
|
|
465
478
|
#
|
466
479
|
def SMTP.start(address, port = nil, *args, helo: nil,
|
467
480
|
user: nil, secret: nil, password: nil, authtype: nil,
|
468
|
-
tls_verify: true, tls_hostname: nil,
|
481
|
+
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
|
469
482
|
&block)
|
470
483
|
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
|
471
484
|
helo ||= args[0] || 'localhost'
|
472
485
|
user ||= args[1]
|
473
486
|
secret ||= password || args[2]
|
474
487
|
authtype ||= args[3]
|
475
|
-
new(address, port).start(helo: helo, user: user, secret: secret, authtype: authtype, tls_verify: tls_verify, tls_hostname: tls_hostname, &block)
|
488
|
+
new(address, port).start(helo: helo, user: user, secret: secret, authtype: authtype, tls_verify: tls_verify, tls_hostname: tls_hostname, ssl_context_params: ssl_context_params, &block)
|
476
489
|
end
|
477
490
|
|
478
491
|
# +true+ if the SMTP session has been started.
|
@@ -482,7 +495,7 @@ module Net
|
|
482
495
|
|
483
496
|
#
|
484
497
|
# :call-seq:
|
485
|
-
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil) { |smtp| ... }
|
498
|
+
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
|
486
499
|
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
487
500
|
#
|
488
501
|
# Opens a TCP connection and starts the SMTP session.
|
@@ -501,6 +514,11 @@ module Net
|
|
501
514
|
# If the hostname in the server certificate is different from +address+,
|
502
515
|
# it can be specified with +tls_hostname+.
|
503
516
|
#
|
517
|
+
# Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
|
518
|
+
# +OpenSSL::SSL::SSLContext#set_params+
|
519
|
+
#
|
520
|
+
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
521
|
+
#
|
504
522
|
# === Block Usage
|
505
523
|
#
|
506
524
|
# When this methods is called with a block, the newly-started SMTP
|
@@ -539,19 +557,25 @@ module Net
|
|
539
557
|
# * IOError
|
540
558
|
#
|
541
559
|
def start(*args, helo: nil,
|
542
|
-
user: nil, secret: nil, password: nil, authtype: nil, tls_verify: true, tls_hostname: nil)
|
560
|
+
user: nil, secret: nil, password: nil, authtype: nil, tls_verify: true, tls_hostname: nil, ssl_context_params: nil)
|
543
561
|
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
|
544
562
|
helo ||= args[0] || 'localhost'
|
545
563
|
user ||= args[1]
|
546
564
|
secret ||= password || args[2]
|
547
565
|
authtype ||= args[3]
|
548
|
-
if
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
566
|
+
if defined?(OpenSSL::VERSION)
|
567
|
+
ssl_context_params = ssl_context_params ? ssl_context_params : {}
|
568
|
+
unless ssl_context_params.has_key?(:verify_mode)
|
569
|
+
ssl_context_params[:verify_mode] = tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
570
|
+
end
|
571
|
+
if @tls && @ssl_context_tls.nil?
|
572
|
+
@ssl_context_tls = SMTP.default_ssl_context(ssl_context_params)
|
573
|
+
end
|
574
|
+
if @starttls && @ssl_context_starttls.nil?
|
575
|
+
@ssl_context_starttls = SMTP.default_ssl_context(ssl_context_params)
|
576
|
+
end
|
577
|
+
@tls_hostname = tls_hostname
|
553
578
|
end
|
554
|
-
@tls_hostname = tls_hostname
|
555
579
|
if block_given?
|
556
580
|
begin
|
557
581
|
do_start helo, user, secret, authtype
|
@@ -575,7 +599,12 @@ module Net
|
|
575
599
|
private
|
576
600
|
|
577
601
|
def tcp_socket(address, port)
|
578
|
-
|
602
|
+
begin
|
603
|
+
Socket.tcp address, port, nil, nil, connect_timeout: @open_timeout
|
604
|
+
rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
|
605
|
+
raise Net::OpenTimeout, "Timeout to open TCP connection to "\
|
606
|
+
"#{address}:#{port} (exceeds #{@open_timeout} seconds)"
|
607
|
+
end
|
579
608
|
end
|
580
609
|
|
581
610
|
def do_start(helo_domain, user, secret, authtype)
|
@@ -584,17 +613,14 @@ module Net
|
|
584
613
|
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
585
614
|
check_auth_args user, secret
|
586
615
|
end
|
587
|
-
s =
|
588
|
-
tcp_socket(@address, @port)
|
589
|
-
end
|
616
|
+
s = tcp_socket(@address, @port)
|
590
617
|
logging "Connection opened: #{@address}:#{@port}"
|
591
618
|
@socket = new_internet_message_io(tls? ? tlsconnect(s, @ssl_context_tls) : s)
|
592
619
|
check_response critical { recv_response() }
|
593
620
|
do_helo helo_domain
|
594
621
|
if ! tls? and (starttls_always? or (capable_starttls? and starttls_auto?))
|
595
622
|
unless capable_starttls?
|
596
|
-
raise SMTPUnsupportedCommand,
|
597
|
-
"STARTTLS is not supported on this server"
|
623
|
+
raise SMTPUnsupportedCommand.new(nil, message: "STARTTLS is not supported on this server")
|
598
624
|
end
|
599
625
|
starttls
|
600
626
|
@socket = new_internet_message_io(tlsconnect(s, @ssl_context_starttls))
|
@@ -620,11 +646,8 @@ module Net
|
|
620
646
|
s = ssl_socket(s, context)
|
621
647
|
logging "TLS connection started"
|
622
648
|
s.sync_close = true
|
623
|
-
s.hostname = @tls_hostname || @address
|
649
|
+
s.hostname = @tls_hostname || @address
|
624
650
|
ssl_socket_connect(s, @open_timeout)
|
625
|
-
if context.verify_mode && context.verify_mode != OpenSSL::SSL::VERIFY_NONE
|
626
|
-
s.post_connection_check(@tls_hostname || @address)
|
627
|
-
end
|
628
651
|
verified = true
|
629
652
|
s
|
630
653
|
ensure
|
@@ -1000,25 +1023,25 @@ module Net
|
|
1000
1023
|
|
1001
1024
|
def check_response(res)
|
1002
1025
|
unless res.success?
|
1003
|
-
raise res.exception_class
|
1026
|
+
raise res.exception_class.new(res)
|
1004
1027
|
end
|
1005
1028
|
end
|
1006
1029
|
|
1007
1030
|
def check_continue(res)
|
1008
1031
|
unless res.continue?
|
1009
|
-
raise SMTPUnknownError, "could not get 3xx (#{res.status}: #{res.string})"
|
1032
|
+
raise SMTPUnknownError.new(res, message: "could not get 3xx (#{res.status}: #{res.string})")
|
1010
1033
|
end
|
1011
1034
|
end
|
1012
1035
|
|
1013
1036
|
def check_auth_response(res)
|
1014
1037
|
unless res.success?
|
1015
|
-
raise SMTPAuthenticationError
|
1038
|
+
raise SMTPAuthenticationError.new(res)
|
1016
1039
|
end
|
1017
1040
|
end
|
1018
1041
|
|
1019
1042
|
def check_auth_continue(res)
|
1020
1043
|
unless res.continue?
|
1021
|
-
raise res.exception_class
|
1044
|
+
raise res.exception_class.new(res)
|
1022
1045
|
end
|
1023
1046
|
end
|
1024
1047
|
|
data/net-smtp.gemspec
CHANGED
@@ -22,12 +22,14 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
23
23
|
spec.metadata["source_code_uri"] = spec.homepage
|
24
24
|
|
25
|
-
spec.files =
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
spec.files = %w[
|
26
|
+
LICENSE.txt
|
27
|
+
lib/net/smtp.rb
|
28
|
+
net-smtp.gemspec
|
29
|
+
]
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
32
|
spec.add_dependency "net-protocol"
|
33
|
+
spec.add_dependency "digest"
|
34
|
+
spec.add_dependency "timeout"
|
33
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-smtp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-protocol
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: digest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: timeout
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: Simple Mail Transfer Protocol client library for Ruby.
|
28
56
|
email:
|
29
57
|
- matz@ruby-lang.org
|
@@ -31,15 +59,7 @@ executables: []
|
|
31
59
|
extensions: []
|
32
60
|
extra_rdoc_files: []
|
33
61
|
files:
|
34
|
-
- ".github/workflows/test.yml"
|
35
|
-
- ".gitignore"
|
36
|
-
- Gemfile
|
37
62
|
- LICENSE.txt
|
38
|
-
- NEWS.md
|
39
|
-
- README.md
|
40
|
-
- Rakefile
|
41
|
-
- bin/console
|
42
|
-
- bin/setup
|
43
63
|
- lib/net/smtp.rb
|
44
64
|
- net-smtp.gemspec
|
45
65
|
homepage: https://github.com/ruby/net-smtp
|
@@ -64,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
84
|
- !ruby/object:Gem::Version
|
65
85
|
version: '0'
|
66
86
|
requirements: []
|
67
|
-
rubygems_version: 3.2.
|
87
|
+
rubygems_version: 3.2.22
|
68
88
|
signing_key:
|
69
89
|
specification_version: 4
|
70
90
|
summary: Simple Mail Transfer Protocol client library for Ruby.
|
data/.github/workflows/test.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
name: test
|
2
|
-
|
3
|
-
on: [push, pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
-
strategy:
|
9
|
-
matrix:
|
10
|
-
ruby: [ 2.7, 2.6, 2.5, head ]
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
12
|
-
runs-on: ${{ matrix.os }}
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@master
|
15
|
-
- name: Set up Ruby
|
16
|
-
uses: ruby/setup-ruby@v1
|
17
|
-
with:
|
18
|
-
ruby-version: ${{ matrix.ruby }}
|
19
|
-
- name: Install dependencies
|
20
|
-
run: |
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
23
|
-
- name: Run test
|
24
|
-
run: rake test
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/NEWS.md
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# NEWS
|
2
|
-
|
3
|
-
## Version 0.2.0 (2020-11-15)
|
4
|
-
|
5
|
-
### Incompatible changes
|
6
|
-
|
7
|
-
* Verify the server's certificate by default.
|
8
|
-
If you don't want verification, specify `start(tls_verify: false)`.
|
9
|
-
<https://github.com/ruby/net-smtp/pull/12>
|
10
|
-
|
11
|
-
* Use STARTTLS by default if possible.
|
12
|
-
If you don't want starttls, specify:
|
13
|
-
```
|
14
|
-
smtp = Net::SMTP.new(hostname, port)
|
15
|
-
smtp.disable_starttls
|
16
|
-
smtp.start do |s|
|
17
|
-
s.send_message ....
|
18
|
-
end
|
19
|
-
```
|
20
|
-
<https://github.com/ruby/net-smtp/pull/9>
|
21
|
-
|
22
|
-
### Improvements
|
23
|
-
|
24
|
-
* Net::SMTP.start and Net::SMTP#start arguments are keyword arguments.
|
25
|
-
```
|
26
|
-
start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
|
27
|
-
```
|
28
|
-
`password` is an alias of `secret`.
|
29
|
-
<https://github.com/ruby/net-smtp/pull/7>
|
30
|
-
|
31
|
-
* Add `tls_hostname` parameter to `start()`.
|
32
|
-
If you want to use a different hostname than the certificate for the connection, you can specify the certificate hostname with `tls_hostname`.
|
33
|
-
<https://github.com/ruby/net-smtp/pull/14>
|
34
|
-
|
35
|
-
* Add SNI support to net/smtp <https://github.com/ruby/net-smtp/pull/4>
|
36
|
-
|
37
|
-
### Fixes
|
38
|
-
|
39
|
-
* enable_starttls before disable_tls causes an error. <https://github.com/ruby/net-smtp/pull/10>
|
40
|
-
* TLS should not check the hostname when verify_mode is disabled. <https://github.com/ruby/net-smtp/pull/6>
|
41
|
-
|
42
|
-
## Version 0.1.0 (2019-12-03)
|
43
|
-
|
44
|
-
This is the first release of net-smtp gem.
|
data/README.md
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# Net::SMTP
|
2
|
-
|
3
|
-
This library provides functionality to send internet mail via SMTP, the Simple Mail Transfer Protocol.
|
4
|
-
|
5
|
-
For details of SMTP itself, see [RFC2821] (http://www.ietf.org/rfc/rfc2821.txt).
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'net-smtp'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install net-smtp
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
### Sending Messages
|
26
|
-
|
27
|
-
You must open a connection to an SMTP server before sending messages.
|
28
|
-
The first argument is the address of your SMTP server, and the second
|
29
|
-
argument is the port number. Using SMTP.start with a block is the simplest
|
30
|
-
way to do this. This way, the SMTP connection is closed automatically
|
31
|
-
after the block is executed.
|
32
|
-
|
33
|
-
```ruby
|
34
|
-
require 'net/smtp'
|
35
|
-
Net::SMTP.start('your.smtp.server', 25) do |smtp|
|
36
|
-
# Use the SMTP object smtp only in this block.
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
|
-
Replace 'your.smtp.server' with your SMTP server. Normally
|
41
|
-
your system manager or internet provider supplies a server
|
42
|
-
for you.
|
43
|
-
|
44
|
-
Then you can send messages.
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
msgstr = <<END_OF_MESSAGE
|
48
|
-
From: Your Name <your@mail.address>
|
49
|
-
To: Destination Address <someone@example.com>
|
50
|
-
Subject: test message
|
51
|
-
Date: Sat, 23 Jun 2001 16:26:43 +0900
|
52
|
-
Message-Id: <unique.message.id.string@example.com>
|
53
|
-
|
54
|
-
This is a test message.
|
55
|
-
END_OF_MESSAGE
|
56
|
-
|
57
|
-
require 'net/smtp'
|
58
|
-
Net::SMTP.start('your.smtp.server', 25) do |smtp|
|
59
|
-
smtp.send_message msgstr,
|
60
|
-
'your@mail.address',
|
61
|
-
'his_address@example.com'
|
62
|
-
end
|
63
|
-
```
|
64
|
-
|
65
|
-
### Closing the Session
|
66
|
-
|
67
|
-
You MUST close the SMTP session after sending messages, by calling
|
68
|
-
the #finish method:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
# using SMTP#finish
|
72
|
-
smtp = Net::SMTP.start('your.smtp.server', 25)
|
73
|
-
smtp.send_message msgstr, 'from@address', 'to@address'
|
74
|
-
smtp.finish
|
75
|
-
```
|
76
|
-
|
77
|
-
You can also use the block form of SMTP.start/SMTP#start. This closes
|
78
|
-
the SMTP session automatically:
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
# using block form of SMTP.start
|
82
|
-
Net::SMTP.start('your.smtp.server', 25) do |smtp|
|
83
|
-
smtp.send_message msgstr, 'from@address', 'to@address'
|
84
|
-
end
|
85
|
-
```
|
86
|
-
|
87
|
-
I strongly recommend this scheme. This form is simpler and more robust.
|
88
|
-
|
89
|
-
## Development
|
90
|
-
|
91
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
|
-
|
93
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
|
-
|
95
|
-
## Contributing
|
96
|
-
|
97
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/net-smtp.
|
data/Rakefile
DELETED
data/bin/console
DELETED