net-smtp 0.2.1 → 0.3.0
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 +76 -42
- 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: a873c949eb563b55b9ea2d29eaecdf2bad09006b7cc2aab14954971021619de1
|
4
|
+
data.tar.gz: c7ed69e3a3e56805953b5ff7ed8f31288eeb4bd113a13e559b38fca5fd85e1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87fcd365f156b81c1124182b09973665607f201909e3bdd8463a007dadda060f6cde0069d4c8db9127233a61531b276b9a0b15e93b77f691a04baacd4c09c6cc
|
7
|
+
data.tar.gz: d8930794d97b2c1dbb8e507bc72b6a4e2f58da8f7e14a6546e87aed8082bbaf7be7c0cde7adeb6c80f66d57c6237edeaf5bc07fbbba6e63905e7c5dcf3777ba1
|
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.
|
182
|
+
VERSION = "0.3.0"
|
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
|
|
@@ -207,11 +215,23 @@ module Net
|
|
207
215
|
# server. +port+ is the port to connect to; it defaults to
|
208
216
|
# port 25.
|
209
217
|
#
|
218
|
+
# If +tls+ is true, enable TLS. The default is false.
|
219
|
+
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
|
220
|
+
# if false, disable STARTTLS.
|
221
|
+
#
|
222
|
+
# If +tls_verify+ is true, verify the server's certificate. The default is true.
|
223
|
+
# If the hostname in the server certificate is different from +address+,
|
224
|
+
# it can be specified with +tls_hostname+.
|
225
|
+
#
|
226
|
+
# Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
|
227
|
+
# +OpenSSL::SSL::SSLContext#set_params+
|
228
|
+
#
|
229
|
+
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
210
230
|
# This method does not open the TCP connection. You can use
|
211
231
|
# SMTP.start instead of SMTP.new if you want to do everything
|
212
232
|
# at once. Otherwise, follow SMTP.new with SMTP#start.
|
213
233
|
#
|
214
|
-
def initialize(address, port = nil)
|
234
|
+
def initialize(address, port = nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil)
|
215
235
|
@address = address
|
216
236
|
@port = (port || SMTP.default_port)
|
217
237
|
@esmtp = true
|
@@ -222,10 +242,13 @@ module Net
|
|
222
242
|
@read_timeout = 60
|
223
243
|
@error_occurred = false
|
224
244
|
@debug_output = nil
|
225
|
-
@tls =
|
226
|
-
@starttls =
|
245
|
+
@tls = tls
|
246
|
+
@starttls = starttls
|
227
247
|
@ssl_context_tls = nil
|
228
248
|
@ssl_context_starttls = nil
|
249
|
+
@tls_verify = tls_verify
|
250
|
+
@tls_hostname = tls_hostname
|
251
|
+
@ssl_context_params = ssl_context_params
|
229
252
|
end
|
230
253
|
|
231
254
|
# Provide human-readable stringification of class state.
|
@@ -301,7 +324,7 @@ module Net
|
|
301
324
|
# this object. Must be called before the connection is established
|
302
325
|
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
|
303
326
|
def enable_tls(context = nil)
|
304
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
327
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
305
328
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @starttls == :always
|
306
329
|
@tls = true
|
307
330
|
@ssl_context_tls = context
|
@@ -338,7 +361,7 @@ module Net
|
|
338
361
|
# Enables SMTP/TLS (STARTTLS) for this object.
|
339
362
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
340
363
|
def enable_starttls(context = nil)
|
341
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
364
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
342
365
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
343
366
|
@starttls = :always
|
344
367
|
@ssl_context_starttls = context
|
@@ -347,7 +370,7 @@ module Net
|
|
347
370
|
# Enables SMTP/TLS (STARTTLS) for this object if server accepts.
|
348
371
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
349
372
|
def enable_starttls_auto(context = nil)
|
350
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
373
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
351
374
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
352
375
|
@starttls = :auto
|
353
376
|
@ssl_context_starttls = context
|
@@ -409,14 +432,14 @@ module Net
|
|
409
432
|
|
410
433
|
#
|
411
434
|
# :call-seq:
|
412
|
-
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil) { |smtp| ... }
|
435
|
+
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
|
413
436
|
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
414
437
|
#
|
415
438
|
# Creates a new Net::SMTP object and connects to the server.
|
416
439
|
#
|
417
440
|
# This method is equivalent to:
|
418
441
|
#
|
419
|
-
# Net::SMTP.new(address, port).start(helo: helo_domain, user: account, secret: password, authtype: authtype, tls_verify: flag, tls_hostname: hostname)
|
442
|
+
# 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
443
|
#
|
421
444
|
# === Example
|
422
445
|
#
|
@@ -446,10 +469,20 @@ module Net
|
|
446
469
|
# or other authentication token; and +authtype+ is the authentication
|
447
470
|
# type, one of :plain, :login, or :cram_md5. See the discussion of
|
448
471
|
# SMTP Authentication in the overview notes.
|
472
|
+
#
|
473
|
+
# If +tls+ is true, enable TLS. The default is false.
|
474
|
+
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
|
475
|
+
# if false, disable STARTTLS.
|
476
|
+
#
|
449
477
|
# If +tls_verify+ is true, verify the server's certificate. The default is true.
|
450
478
|
# If the hostname in the server certificate is different from +address+,
|
451
479
|
# it can be specified with +tls_hostname+.
|
452
480
|
#
|
481
|
+
# Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
|
482
|
+
# +OpenSSL::SSL::SSLContext#set_params+
|
483
|
+
#
|
484
|
+
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
485
|
+
#
|
453
486
|
# === Errors
|
454
487
|
#
|
455
488
|
# This method may raise:
|
@@ -465,14 +498,15 @@ module Net
|
|
465
498
|
#
|
466
499
|
def SMTP.start(address, port = nil, *args, helo: nil,
|
467
500
|
user: nil, secret: nil, password: nil, authtype: nil,
|
468
|
-
|
501
|
+
tls: false, starttls: :auto,
|
502
|
+
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
|
469
503
|
&block)
|
470
504
|
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
|
471
505
|
helo ||= args[0] || 'localhost'
|
472
506
|
user ||= args[1]
|
473
507
|
secret ||= password || args[2]
|
474
508
|
authtype ||= args[3]
|
475
|
-
new(address, port).start(helo: helo, user: user, secret: secret, authtype: authtype,
|
509
|
+
new(address, port, tls: tls, starttls: starttls, tls_verify: tls_verify, tls_hostname: tls_hostname, ssl_context_params: ssl_context_params).start(helo: helo, user: user, secret: secret, authtype: authtype, &block)
|
476
510
|
end
|
477
511
|
|
478
512
|
# +true+ if the SMTP session has been started.
|
@@ -482,7 +516,7 @@ module Net
|
|
482
516
|
|
483
517
|
#
|
484
518
|
# :call-seq:
|
485
|
-
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil
|
519
|
+
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
|
486
520
|
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
487
521
|
#
|
488
522
|
# Opens a TCP connection and starts the SMTP session.
|
@@ -497,9 +531,6 @@ module Net
|
|
497
531
|
# the type of authentication to attempt; it must be one of
|
498
532
|
# :login, :plain, and :cram_md5. See the notes on SMTP Authentication
|
499
533
|
# in the overview.
|
500
|
-
# If +tls_verify+ is true, verify the server's certificate. The default is true.
|
501
|
-
# If the hostname in the server certificate is different from +address+,
|
502
|
-
# it can be specified with +tls_hostname+.
|
503
534
|
#
|
504
535
|
# === Block Usage
|
505
536
|
#
|
@@ -538,20 +569,24 @@ module Net
|
|
538
569
|
# * Net::ReadTimeout
|
539
570
|
# * IOError
|
540
571
|
#
|
541
|
-
def start(*args, helo: nil,
|
542
|
-
user: nil, secret: nil, password: nil, authtype: nil, tls_verify: true, tls_hostname: nil)
|
572
|
+
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
|
543
573
|
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
|
544
574
|
helo ||= args[0] || 'localhost'
|
545
575
|
user ||= args[1]
|
546
576
|
secret ||= password || args[2]
|
547
577
|
authtype ||= args[3]
|
548
|
-
if
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
578
|
+
if defined?(OpenSSL::VERSION)
|
579
|
+
ssl_context_params = @ssl_context_params || {}
|
580
|
+
unless ssl_context_params.has_key?(:verify_mode)
|
581
|
+
ssl_context_params[:verify_mode] = @tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
582
|
+
end
|
583
|
+
if @tls && @ssl_context_tls.nil?
|
584
|
+
@ssl_context_tls = SMTP.default_ssl_context(ssl_context_params)
|
585
|
+
end
|
586
|
+
if @starttls && @ssl_context_starttls.nil?
|
587
|
+
@ssl_context_starttls = SMTP.default_ssl_context(ssl_context_params)
|
588
|
+
end
|
553
589
|
end
|
554
|
-
@tls_hostname = tls_hostname
|
555
590
|
if block_given?
|
556
591
|
begin
|
557
592
|
do_start helo, user, secret, authtype
|
@@ -575,7 +610,12 @@ module Net
|
|
575
610
|
private
|
576
611
|
|
577
612
|
def tcp_socket(address, port)
|
578
|
-
|
613
|
+
begin
|
614
|
+
Socket.tcp address, port, nil, nil, connect_timeout: @open_timeout
|
615
|
+
rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
|
616
|
+
raise Net::OpenTimeout, "Timeout to open TCP connection to "\
|
617
|
+
"#{address}:#{port} (exceeds #{@open_timeout} seconds)"
|
618
|
+
end
|
579
619
|
end
|
580
620
|
|
581
621
|
def do_start(helo_domain, user, secret, authtype)
|
@@ -584,17 +624,14 @@ module Net
|
|
584
624
|
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
585
625
|
check_auth_args user, secret
|
586
626
|
end
|
587
|
-
s =
|
588
|
-
tcp_socket(@address, @port)
|
589
|
-
end
|
627
|
+
s = tcp_socket(@address, @port)
|
590
628
|
logging "Connection opened: #{@address}:#{@port}"
|
591
629
|
@socket = new_internet_message_io(tls? ? tlsconnect(s, @ssl_context_tls) : s)
|
592
630
|
check_response critical { recv_response() }
|
593
631
|
do_helo helo_domain
|
594
632
|
if ! tls? and (starttls_always? or (capable_starttls? and starttls_auto?))
|
595
633
|
unless capable_starttls?
|
596
|
-
raise SMTPUnsupportedCommand,
|
597
|
-
"STARTTLS is not supported on this server"
|
634
|
+
raise SMTPUnsupportedCommand.new(nil, message: "STARTTLS is not supported on this server")
|
598
635
|
end
|
599
636
|
starttls
|
600
637
|
@socket = new_internet_message_io(tlsconnect(s, @ssl_context_starttls))
|
@@ -620,11 +657,8 @@ module Net
|
|
620
657
|
s = ssl_socket(s, context)
|
621
658
|
logging "TLS connection started"
|
622
659
|
s.sync_close = true
|
623
|
-
s.hostname = @tls_hostname || @address
|
660
|
+
s.hostname = @tls_hostname || @address
|
624
661
|
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
662
|
verified = true
|
629
663
|
s
|
630
664
|
ensure
|
@@ -1000,25 +1034,25 @@ module Net
|
|
1000
1034
|
|
1001
1035
|
def check_response(res)
|
1002
1036
|
unless res.success?
|
1003
|
-
raise res.exception_class
|
1037
|
+
raise res.exception_class.new(res)
|
1004
1038
|
end
|
1005
1039
|
end
|
1006
1040
|
|
1007
1041
|
def check_continue(res)
|
1008
1042
|
unless res.continue?
|
1009
|
-
raise SMTPUnknownError, "could not get 3xx (#{res.status}: #{res.string})"
|
1043
|
+
raise SMTPUnknownError.new(res, message: "could not get 3xx (#{res.status}: #{res.string})")
|
1010
1044
|
end
|
1011
1045
|
end
|
1012
1046
|
|
1013
1047
|
def check_auth_response(res)
|
1014
1048
|
unless res.success?
|
1015
|
-
raise SMTPAuthenticationError
|
1049
|
+
raise SMTPAuthenticationError.new(res)
|
1016
1050
|
end
|
1017
1051
|
end
|
1018
1052
|
|
1019
1053
|
def check_auth_continue(res)
|
1020
1054
|
unless res.continue?
|
1021
|
-
raise res.exception_class
|
1055
|
+
raise res.exception_class.new(res)
|
1022
1056
|
end
|
1023
1057
|
end
|
1024
1058
|
|
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.
|
4
|
+
version: 0.3.0
|
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-14 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