net-smtp 0.2.0 → 0.3.1
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 +134 -51
- data/net-smtp.gemspec +11 -7
- metadata +49 -14
- 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: fbf12984985ffef0271f09805060b2cfa5e72eb3955c8ce51ee8076b427e1a02
|
4
|
+
data.tar.gz: 17c6420b495abe8b17446b1e667681b2680b02d894b3ce1e4ef6cffaa26ad1df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9372a9673256cc280600a1367a0c92bed91250209736b4b54c7219c115b1006e9fc66d465367729f53ef393b9a8077b33f11f7578365d9cb84051e44b86976
|
7
|
+
data.tar.gz: 0f7da80c1d40216684ff0927637b14dfb5597638913a0aa3a8f2ca68a3fc89724926736c719715171b7bcab915a9504016f10356b2622bc6da9e5f51238f8e52
|
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.1"
|
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,12 +242,24 @@ 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
|
|
254
|
+
# If +true+, verify th server's certificate.
|
255
|
+
attr_accessor :tls_verify
|
256
|
+
|
257
|
+
# The hostname for verifying hostname in the server certificatate.
|
258
|
+
attr_accessor :tls_hostname
|
259
|
+
|
260
|
+
# Hash for additional SSLContext parameters.
|
261
|
+
attr_accessor :ssl_context_params
|
262
|
+
|
231
263
|
# Provide human-readable stringification of class state.
|
232
264
|
def inspect
|
233
265
|
"#<#{self.class} #{@address}:#{@port} started=#{@started}>"
|
@@ -251,11 +283,14 @@ module Net
|
|
251
283
|
capable?('STARTTLS')
|
252
284
|
end
|
253
285
|
|
286
|
+
# true if the EHLO response contains +key+.
|
254
287
|
def capable?(key)
|
255
288
|
return nil unless @capabilities
|
256
289
|
@capabilities[key] ? true : false
|
257
290
|
end
|
258
|
-
|
291
|
+
|
292
|
+
# The server capabilities by EHLO response
|
293
|
+
attr_reader :capabilities
|
259
294
|
|
260
295
|
# true if server advertises AUTH PLAIN.
|
261
296
|
# You cannot get valid value before opening SMTP session.
|
@@ -301,7 +336,7 @@ module Net
|
|
301
336
|
# this object. Must be called before the connection is established
|
302
337
|
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
|
303
338
|
def enable_tls(context = nil)
|
304
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
339
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
305
340
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @starttls == :always
|
306
341
|
@tls = true
|
307
342
|
@ssl_context_tls = context
|
@@ -338,7 +373,7 @@ module Net
|
|
338
373
|
# Enables SMTP/TLS (STARTTLS) for this object.
|
339
374
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
340
375
|
def enable_starttls(context = nil)
|
341
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
376
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
342
377
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
343
378
|
@starttls = :always
|
344
379
|
@ssl_context_starttls = context
|
@@ -347,7 +382,7 @@ module Net
|
|
347
382
|
# Enables SMTP/TLS (STARTTLS) for this object if server accepts.
|
348
383
|
# +context+ is a OpenSSL::SSL::SSLContext object.
|
349
384
|
def enable_starttls_auto(context = nil)
|
350
|
-
raise 'openssl library not installed' unless defined?(OpenSSL)
|
385
|
+
raise 'openssl library not installed' unless defined?(OpenSSL::VERSION)
|
351
386
|
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
|
352
387
|
@starttls = :auto
|
353
388
|
@ssl_context_starttls = context
|
@@ -409,14 +444,14 @@ module Net
|
|
409
444
|
|
410
445
|
#
|
411
446
|
# :call-seq:
|
412
|
-
# start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil, tls_verify: true, tls_hostname: nil) { |smtp| ... }
|
447
|
+
# 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
448
|
# start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
414
449
|
#
|
415
450
|
# Creates a new Net::SMTP object and connects to the server.
|
416
451
|
#
|
417
452
|
# This method is equivalent to:
|
418
453
|
#
|
419
|
-
# Net::SMTP.new(address, port).start(helo: helo_domain, user: account, secret: password, authtype: authtype, tls_verify: flag, tls_hostname: hostname)
|
454
|
+
# 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
455
|
#
|
421
456
|
# === Example
|
422
457
|
#
|
@@ -446,10 +481,20 @@ module Net
|
|
446
481
|
# or other authentication token; and +authtype+ is the authentication
|
447
482
|
# type, one of :plain, :login, or :cram_md5. See the discussion of
|
448
483
|
# SMTP Authentication in the overview notes.
|
484
|
+
#
|
485
|
+
# If +tls+ is true, enable TLS. The default is false.
|
486
|
+
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
|
487
|
+
# if false, disable STARTTLS.
|
488
|
+
#
|
449
489
|
# If +tls_verify+ is true, verify the server's certificate. The default is true.
|
450
490
|
# If the hostname in the server certificate is different from +address+,
|
451
491
|
# it can be specified with +tls_hostname+.
|
452
492
|
#
|
493
|
+
# Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
|
494
|
+
# +OpenSSL::SSL::SSLContext#set_params+
|
495
|
+
#
|
496
|
+
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
497
|
+
#
|
453
498
|
# === Errors
|
454
499
|
#
|
455
500
|
# This method may raise:
|
@@ -465,14 +510,15 @@ module Net
|
|
465
510
|
#
|
466
511
|
def SMTP.start(address, port = nil, *args, helo: nil,
|
467
512
|
user: nil, secret: nil, password: nil, authtype: nil,
|
468
|
-
|
513
|
+
tls: false, starttls: :auto,
|
514
|
+
tls_verify: true, tls_hostname: nil, ssl_context_params: nil,
|
469
515
|
&block)
|
470
516
|
raise ArgumentError, "wrong number of arguments (given #{args.size + 2}, expected 1..6)" if args.size > 4
|
471
517
|
helo ||= args[0] || 'localhost'
|
472
518
|
user ||= args[1]
|
473
519
|
secret ||= password || args[2]
|
474
520
|
authtype ||= args[3]
|
475
|
-
new(address, port).start(helo: helo, user: user, secret: secret, authtype: authtype,
|
521
|
+
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
522
|
end
|
477
523
|
|
478
524
|
# +true+ if the SMTP session has been started.
|
@@ -482,7 +528,7 @@ module Net
|
|
482
528
|
|
483
529
|
#
|
484
530
|
# :call-seq:
|
485
|
-
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil
|
531
|
+
# start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
|
486
532
|
# start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
|
487
533
|
#
|
488
534
|
# Opens a TCP connection and starts the SMTP session.
|
@@ -497,9 +543,6 @@ module Net
|
|
497
543
|
# the type of authentication to attempt; it must be one of
|
498
544
|
# :login, :plain, and :cram_md5. See the notes on SMTP Authentication
|
499
545
|
# 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
546
|
#
|
504
547
|
# === Block Usage
|
505
548
|
#
|
@@ -538,20 +581,24 @@ module Net
|
|
538
581
|
# * Net::ReadTimeout
|
539
582
|
# * IOError
|
540
583
|
#
|
541
|
-
def start(*args, helo: nil,
|
542
|
-
user: nil, secret: nil, password: nil, authtype: nil, tls_verify: true, tls_hostname: nil)
|
584
|
+
def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil)
|
543
585
|
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..4)" if args.size > 4
|
544
586
|
helo ||= args[0] || 'localhost'
|
545
587
|
user ||= args[1]
|
546
588
|
secret ||= password || args[2]
|
547
589
|
authtype ||= args[3]
|
548
|
-
if
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
590
|
+
if defined?(OpenSSL::VERSION)
|
591
|
+
ssl_context_params = @ssl_context_params || {}
|
592
|
+
unless ssl_context_params.has_key?(:verify_mode)
|
593
|
+
ssl_context_params[:verify_mode] = @tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
594
|
+
end
|
595
|
+
if @tls && @ssl_context_tls.nil?
|
596
|
+
@ssl_context_tls = SMTP.default_ssl_context(ssl_context_params)
|
597
|
+
end
|
598
|
+
if @starttls && @ssl_context_starttls.nil?
|
599
|
+
@ssl_context_starttls = SMTP.default_ssl_context(ssl_context_params)
|
600
|
+
end
|
553
601
|
end
|
554
|
-
@tls_hostname = tls_hostname
|
555
602
|
if block_given?
|
556
603
|
begin
|
557
604
|
do_start helo, user, secret, authtype
|
@@ -575,7 +622,12 @@ module Net
|
|
575
622
|
private
|
576
623
|
|
577
624
|
def tcp_socket(address, port)
|
578
|
-
|
625
|
+
begin
|
626
|
+
Socket.tcp address, port, nil, nil, connect_timeout: @open_timeout
|
627
|
+
rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
|
628
|
+
raise Net::OpenTimeout, "Timeout to open TCP connection to "\
|
629
|
+
"#{address}:#{port} (exceeds #{@open_timeout} seconds)"
|
630
|
+
end
|
579
631
|
end
|
580
632
|
|
581
633
|
def do_start(helo_domain, user, secret, authtype)
|
@@ -584,17 +636,14 @@ module Net
|
|
584
636
|
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
585
637
|
check_auth_args user, secret
|
586
638
|
end
|
587
|
-
s =
|
588
|
-
tcp_socket(@address, @port)
|
589
|
-
end
|
639
|
+
s = tcp_socket(@address, @port)
|
590
640
|
logging "Connection opened: #{@address}:#{@port}"
|
591
641
|
@socket = new_internet_message_io(tls? ? tlsconnect(s, @ssl_context_tls) : s)
|
592
642
|
check_response critical { recv_response() }
|
593
643
|
do_helo helo_domain
|
594
644
|
if ! tls? and (starttls_always? or (capable_starttls? and starttls_auto?))
|
595
645
|
unless capable_starttls?
|
596
|
-
raise SMTPUnsupportedCommand,
|
597
|
-
"STARTTLS is not supported on this server"
|
646
|
+
raise SMTPUnsupportedCommand.new(nil, message: "STARTTLS is not supported on this server")
|
598
647
|
end
|
599
648
|
starttls
|
600
649
|
@socket = new_internet_message_io(tlsconnect(s, @ssl_context_starttls))
|
@@ -620,11 +669,8 @@ module Net
|
|
620
669
|
s = ssl_socket(s, context)
|
621
670
|
logging "TLS connection started"
|
622
671
|
s.sync_close = true
|
623
|
-
s.hostname = @tls_hostname || @address
|
672
|
+
s.hostname = @tls_hostname || @address
|
624
673
|
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
674
|
verified = true
|
629
675
|
s
|
630
676
|
ensure
|
@@ -669,9 +715,9 @@ module Net
|
|
669
715
|
# binary message with this method. +msgstr+ should include both
|
670
716
|
# the message headers and body.
|
671
717
|
#
|
672
|
-
# +from_addr+ is a String representing the source mail address.
|
718
|
+
# +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
|
673
719
|
#
|
674
|
-
# +to_addr+ is a String or
|
720
|
+
# +to_addr+ is a String or Net::SMTP::Address or Array of them, representing
|
675
721
|
# the destination mail address or addresses.
|
676
722
|
#
|
677
723
|
# === Example
|
@@ -682,6 +728,12 @@ module Net
|
|
682
728
|
# ['dest@example.com', 'dest2@example.com']
|
683
729
|
# end
|
684
730
|
#
|
731
|
+
# Net::SMTP.start('smtp.example.com') do |smtp|
|
732
|
+
# smtp.send_message msgstr,
|
733
|
+
# Net::SMTP::Address.new('from@example.com', size: 12345),
|
734
|
+
# Net::SMTP::Address.new('dest@example.com', notify: :success)
|
735
|
+
# end
|
736
|
+
#
|
685
737
|
# === Errors
|
686
738
|
#
|
687
739
|
# This method may raise:
|
@@ -718,9 +770,9 @@ module Net
|
|
718
770
|
#
|
719
771
|
# === Parameters
|
720
772
|
#
|
721
|
-
# +from_addr+ is a String representing the source mail address.
|
773
|
+
# +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
|
722
774
|
#
|
723
|
-
# +to_addr+ is a String or
|
775
|
+
# +to_addr+ is a String or Net::SMTP::Address or Array of them, representing
|
724
776
|
# the destination mail address or addresses.
|
725
777
|
#
|
726
778
|
# === Example
|
@@ -765,7 +817,7 @@ module Net
|
|
765
817
|
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
|
766
818
|
check_auth_method authtype
|
767
819
|
check_auth_args user, secret
|
768
|
-
|
820
|
+
public_send auth_method(authtype), user, secret
|
769
821
|
end
|
770
822
|
|
771
823
|
def auth_plain(user, secret)
|
@@ -870,8 +922,10 @@ module Net
|
|
870
922
|
getok("EHLO #{domain}")
|
871
923
|
end
|
872
924
|
|
925
|
+
# +from_addr+ is +String+ or +Net::SMTP::Address+
|
873
926
|
def mailfrom(from_addr)
|
874
|
-
|
927
|
+
addr = Address.new(from_addr)
|
928
|
+
getok((["MAIL FROM:<#{addr.address}>"] + addr.parameters).join(' '))
|
875
929
|
end
|
876
930
|
|
877
931
|
def rcptto_list(to_addrs)
|
@@ -882,7 +936,7 @@ module Net
|
|
882
936
|
begin
|
883
937
|
rcptto addr
|
884
938
|
rescue SMTPAuthenticationError
|
885
|
-
unknown_users << addr.dump
|
939
|
+
unknown_users << addr.to_s.dump
|
886
940
|
else
|
887
941
|
ok_users << addr
|
888
942
|
end
|
@@ -895,8 +949,10 @@ module Net
|
|
895
949
|
ret
|
896
950
|
end
|
897
951
|
|
952
|
+
# +to_addr+ is +String+ or +Net::SMTP::Address+
|
898
953
|
def rcptto(to_addr)
|
899
|
-
|
954
|
+
addr = Address.new(to_addr)
|
955
|
+
getok((["RCPT TO:<#{addr.address}>"] + addr.parameters).join(' '))
|
900
956
|
end
|
901
957
|
|
902
958
|
# This method sends a message.
|
@@ -1000,25 +1056,25 @@ module Net
|
|
1000
1056
|
|
1001
1057
|
def check_response(res)
|
1002
1058
|
unless res.success?
|
1003
|
-
raise res.exception_class
|
1059
|
+
raise res.exception_class.new(res)
|
1004
1060
|
end
|
1005
1061
|
end
|
1006
1062
|
|
1007
1063
|
def check_continue(res)
|
1008
1064
|
unless res.continue?
|
1009
|
-
raise SMTPUnknownError, "could not get 3xx (#{res.status}: #{res.string})"
|
1065
|
+
raise SMTPUnknownError.new(res, message: "could not get 3xx (#{res.status}: #{res.string})")
|
1010
1066
|
end
|
1011
1067
|
end
|
1012
1068
|
|
1013
1069
|
def check_auth_response(res)
|
1014
1070
|
unless res.success?
|
1015
|
-
raise SMTPAuthenticationError
|
1071
|
+
raise SMTPAuthenticationError.new(res)
|
1016
1072
|
end
|
1017
1073
|
end
|
1018
1074
|
|
1019
1075
|
def check_auth_continue(res)
|
1020
1076
|
unless res.continue?
|
1021
|
-
raise res.exception_class
|
1077
|
+
raise res.exception_class.new(res)
|
1022
1078
|
end
|
1023
1079
|
end
|
1024
1080
|
|
@@ -1105,6 +1161,33 @@ module Net
|
|
1105
1161
|
@debug_output << msg + "\n" if @debug_output
|
1106
1162
|
end
|
1107
1163
|
|
1164
|
+
# Address with parametres for MAIL or RCPT command
|
1165
|
+
class Address
|
1166
|
+
# mail address [String]
|
1167
|
+
attr_reader :address
|
1168
|
+
# paramters [Array<String>]
|
1169
|
+
attr_reader :parameters
|
1170
|
+
|
1171
|
+
# :call-seq:
|
1172
|
+
# initialize(address, parameter, ...)
|
1173
|
+
#
|
1174
|
+
# address +String+ or +Net::SMTP::Address+
|
1175
|
+
# parameter +String+ or +Hash+
|
1176
|
+
def initialize(address, *args, **kw_args)
|
1177
|
+
if address.kind_of? Address
|
1178
|
+
@address = address.address
|
1179
|
+
@parameters = address.parameters
|
1180
|
+
else
|
1181
|
+
@address = address
|
1182
|
+
@parameters = (args + [kw_args]).map{|param| Array(param)}.flatten(1).map{|param| Array(param).compact.join('=')}
|
1183
|
+
end
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
def to_s
|
1187
|
+
@address
|
1188
|
+
end
|
1189
|
+
end
|
1190
|
+
|
1108
1191
|
end # class SMTP
|
1109
1192
|
|
1110
1193
|
SMTPSession = SMTP # :nodoc:
|
data/net-smtp.gemspec
CHANGED
@@ -16,16 +16,20 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.summary = %q{Simple Mail Transfer Protocol client library for Ruby.}
|
17
17
|
spec.description = %q{Simple Mail Transfer Protocol client library for Ruby.}
|
18
18
|
spec.homepage = "https://github.com/ruby/net-smtp"
|
19
|
-
spec.
|
20
|
-
spec.required_ruby_version = ">= 2.
|
19
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
20
|
+
spec.required_ruby_version = ">= 2.6.0"
|
21
21
|
|
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
|
+
|
32
|
+
spec.add_dependency "net-protocol"
|
33
|
+
spec.add_dependency "digest"
|
34
|
+
spec.add_dependency "timeout"
|
31
35
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
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.1
|
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:
|
12
|
-
dependencies:
|
11
|
+
date: 2021-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-protocol
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
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'
|
13
55
|
description: Simple Mail Transfer Protocol client library for Ruby.
|
14
56
|
email:
|
15
57
|
- matz@ruby-lang.org
|
@@ -17,19 +59,12 @@ executables: []
|
|
17
59
|
extensions: []
|
18
60
|
extra_rdoc_files: []
|
19
61
|
files:
|
20
|
-
- ".github/workflows/test.yml"
|
21
|
-
- ".gitignore"
|
22
|
-
- Gemfile
|
23
62
|
- LICENSE.txt
|
24
|
-
- NEWS.md
|
25
|
-
- README.md
|
26
|
-
- Rakefile
|
27
|
-
- bin/console
|
28
|
-
- bin/setup
|
29
63
|
- lib/net/smtp.rb
|
30
64
|
- net-smtp.gemspec
|
31
65
|
homepage: https://github.com/ruby/net-smtp
|
32
66
|
licenses:
|
67
|
+
- Ruby
|
33
68
|
- BSD-2-Clause
|
34
69
|
metadata:
|
35
70
|
homepage_uri: https://github.com/ruby/net-smtp
|
@@ -42,14 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
77
|
requirements:
|
43
78
|
- - ">="
|
44
79
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.
|
80
|
+
version: 2.6.0
|
46
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
82
|
requirements:
|
48
83
|
- - ">="
|
49
84
|
- !ruby/object:Gem::Version
|
50
85
|
version: '0'
|
51
86
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.3.0.dev
|
53
88
|
signing_key:
|
54
89
|
specification_version: 4
|
55
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