net-smtp 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +19 -0
- data/lib/net/smtp/auth_xoauth2.rb +17 -0
- data/lib/net/smtp/authenticator.rb +12 -1
- data/lib/net/smtp.rb +96 -71
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fcccbe34b29672c33aa7515de88e88dba31882e26a4b6c0a5fc30c5a4eb697d
|
4
|
+
data.tar.gz: 5c47e6453d2cb69365edc7b4e31b17106b73e254e1bc10258f4b14ea780ba889
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6576c5b7dc21982576fa6c3a6e08641e973136148d5d5bcb27fe1e17b4e5fdd802c5f5a6f9f116dd15bf4f2a0e5f95f071ca19d47119cf60c7da9230a64d3a4c
|
7
|
+
data.tar.gz: 9b1c54b2d9a48e384d3b1a67f1aa8b8a2614a383dc31b83d49170f3ed93d69a2058f3c310f72d443f54a0947c1066249105087a1a3addc92965c289354c8156a
|
data/NEWS.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## Version 0.5.0 (2024-03-27)
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Allow case-insensitive strings for SASL mechanism <https://github.com/ruby/net-smtp/pull/64>
|
8
|
+
* Make #auth_capable? public <https://github.com/ruby/net-smtp/pull/63>
|
9
|
+
* Add XOAUTH2 authenticator <https://github.com/ruby/net-smtp/pull/80>
|
10
|
+
|
11
|
+
### Others
|
12
|
+
|
13
|
+
* Remove unused private auth_method <https://github.com/ruby/net-smtp/pull/67>
|
14
|
+
* Delegate checking auth args to the authenticator <https://github.com/ruby/net-smtp/pull/73>
|
15
|
+
* Updated docs, especially TLS and SASL-related <https://github.com/ruby/net-smtp/pull/66>
|
16
|
+
* Renew test certificates <https://github.com/ruby/net-smtp/pull/75>
|
17
|
+
* Fix version extraction to work with non ASCII characters with any LANG <https://github.com/ruby/net-smtp/pull/76>
|
18
|
+
* Replace non-ASCII EM DASH (U+2014) with ASCII hyphen (U+002D) <https://github.com/ruby/net-smtp/pull/78>
|
19
|
+
* Use reusing workflow for Ruby versions <https://github.com/ruby/net-smtp/pull/79>
|
20
|
+
* Make the test suite compatible with --enable-frozen-string-literal <https://github.com/ruby/net-smtp/pull/81>
|
21
|
+
|
3
22
|
## Version 0.4.0 (2023-09-20)
|
4
23
|
|
5
24
|
### Improvements
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Net::SMTP
|
2
|
+
class AuthXoauth2 < Net::SMTP::Authenticator
|
3
|
+
auth_type :xoauth2
|
4
|
+
|
5
|
+
def auth(user, secret)
|
6
|
+
token = xoauth2_string(user, secret)
|
7
|
+
|
8
|
+
finish("AUTH XOAUTH2 #{base64_encode(token)}")
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def xoauth2_string(user, secret)
|
14
|
+
"user=#{user}\1auth=Bearer #{secret}\1\1"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,11 +6,22 @@ module Net
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.auth_type(type)
|
9
|
+
type = type.to_s.upcase.tr(?_, ?-).to_sym
|
9
10
|
Authenticator.auth_classes[type] = self
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.auth_class(type)
|
13
|
-
|
14
|
+
type = type.to_s.upcase.tr(?_, ?-).to_sym
|
15
|
+
Authenticator.auth_classes[type]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.check_args(user_arg = nil, secret_arg = nil, *, **)
|
19
|
+
unless user_arg
|
20
|
+
raise ArgumentError, 'SMTP-AUTH requested but missing user name'
|
21
|
+
end
|
22
|
+
unless secret_arg
|
23
|
+
raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
|
24
|
+
end
|
14
25
|
end
|
15
26
|
|
16
27
|
attr_reader :smtp
|
data/lib/net/smtp.rb
CHANGED
@@ -79,13 +79,13 @@ module Net
|
|
79
79
|
# == What is This Library?
|
80
80
|
#
|
81
81
|
# This library provides functionality to send internet
|
82
|
-
# mail via SMTP, the Simple Mail Transfer Protocol. For details of
|
83
|
-
# SMTP itself, see [RFC5321
|
84
|
-
# This library also implements SMTP authentication, which is often
|
82
|
+
# mail via \SMTP, the Simple Mail Transfer Protocol. For details of
|
83
|
+
# \SMTP itself, see [RFC5321[https://www.rfc-editor.org/rfc/rfc5321.txt]].
|
84
|
+
# This library also implements \SMTP authentication, which is often
|
85
85
|
# necessary for message composers to submit messages to their
|
86
|
-
# outgoing SMTP server, see
|
87
|
-
# [RFC6409
|
88
|
-
# and [SMTPUTF8
|
86
|
+
# outgoing \SMTP server, see
|
87
|
+
# [RFC6409[https://www.rfc-editor.org/rfc/rfc6409.html]],
|
88
|
+
# and [SMTPUTF8[https://www.rfc-editor.org/rfc/rfc6531.txt]], which is
|
89
89
|
# necessary to send messages to/from addresses containing characters
|
90
90
|
# outside the ASCII range.
|
91
91
|
#
|
@@ -93,18 +93,20 @@ module Net
|
|
93
93
|
#
|
94
94
|
# This library does NOT provide functions to compose internet mails.
|
95
95
|
# You must create them by yourself. If you want better mail support,
|
96
|
-
# try
|
96
|
+
# try the mail[https://rubygems.org/gems/mail] or
|
97
|
+
# rmail[https://rubygems.org/gems/rmail] gems, or search for alternatives in
|
97
98
|
# {RubyGems.org}[https://rubygems.org/] or {The Ruby
|
98
99
|
# Toolbox}[https://www.ruby-toolbox.com/].
|
99
100
|
#
|
100
|
-
# FYI: the official specification on internet mail is:
|
101
|
+
# FYI: the official specification on internet mail is:
|
102
|
+
# [RFC5322[https://www.rfc-editor.org/rfc/rfc5322.txt]].
|
101
103
|
#
|
102
104
|
# == Examples
|
103
105
|
#
|
104
106
|
# === Sending Messages
|
105
107
|
#
|
106
|
-
# You must open a connection to an SMTP server before sending messages.
|
107
|
-
# The first argument is the address of your SMTP server, and the second
|
108
|
+
# You must open a connection to an \SMTP server before sending messages.
|
109
|
+
# The first argument is the address of your \SMTP server, and the second
|
108
110
|
# argument is the port number. Using SMTP.start with a block is the simplest
|
109
111
|
# way to do this. This way, the SMTP connection is closed automatically
|
110
112
|
# after the block is executed.
|
@@ -114,7 +116,7 @@ module Net
|
|
114
116
|
# # Use the SMTP object smtp only in this block.
|
115
117
|
# end
|
116
118
|
#
|
117
|
-
# Replace 'your.smtp.server' with your SMTP server. Normally
|
119
|
+
# Replace 'your.smtp.server' with your \SMTP server. Normally
|
118
120
|
# your system manager or internet provider supplies a server
|
119
121
|
# for you.
|
120
122
|
#
|
@@ -147,7 +149,7 @@ module Net
|
|
147
149
|
# smtp.send_message msgstr, 'from@address', 'to@address'
|
148
150
|
# smtp.finish
|
149
151
|
#
|
150
|
-
# You can also use the block form of SMTP.start
|
152
|
+
# You can also use the block form of SMTP.start or SMTP#start. This closes
|
151
153
|
# the SMTP session automatically:
|
152
154
|
#
|
153
155
|
# # using block form of SMTP.start
|
@@ -160,34 +162,37 @@ module Net
|
|
160
162
|
# === HELO domain
|
161
163
|
#
|
162
164
|
# In almost all situations, you must provide a third argument
|
163
|
-
# to SMTP.start
|
165
|
+
# to SMTP.start or SMTP#start. This is the domain name which you are on
|
164
166
|
# (the host to send mail from). It is called the "HELO domain".
|
165
|
-
# The SMTP server will judge whether it should send or reject
|
167
|
+
# The \SMTP server will judge whether it should send or reject
|
166
168
|
# the SMTP session by inspecting the HELO domain.
|
167
169
|
#
|
168
|
-
# Net::SMTP.start('your.smtp.server', 25
|
169
|
-
#
|
170
|
+
# Net::SMTP.start('your.smtp.server', 25, helo: 'mail.from.domain') do |smtp|
|
171
|
+
# smtp.send_message msgstr, 'from@address', 'to@address'
|
172
|
+
# end
|
170
173
|
#
|
171
|
-
# === SMTP Authentication
|
174
|
+
# === \SMTP Authentication
|
172
175
|
#
|
173
|
-
# The Net::SMTP class supports
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
176
|
+
# The Net::SMTP class supports the \SMTP extension for SASL Authentication
|
177
|
+
# [RFC4954[https://www.rfc-editor.org/rfc/rfc4954.html]] and the following
|
178
|
+
# SASL mechanisms: +PLAIN+, +LOGIN+ _(deprecated)_, and +CRAM-MD5+
|
179
|
+
# _(deprecated)_.
|
180
|
+
#
|
181
|
+
# To use \SMTP authentication, pass extra arguments to
|
182
|
+
# SMTP.start or SMTP#start.
|
177
183
|
#
|
178
184
|
# # PLAIN
|
179
|
-
# Net::SMTP.start('your.smtp.server', 25
|
185
|
+
# Net::SMTP.start('your.smtp.server', 25,
|
180
186
|
# user: 'Your Account', secret: 'Your Password', authtype: :plain)
|
181
|
-
# # LOGIN
|
182
|
-
# Net::SMTP.start('your.smtp.server', 25
|
183
|
-
# user: 'Your Account', secret: 'Your Password', authtype: :login)
|
184
187
|
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
+
# Support for other SASL mechanisms-such as +EXTERNAL+, +OAUTHBEARER+,
|
189
|
+
# +SCRAM-SHA-256+, and +XOAUTH2+-will be added in a future release.
|
190
|
+
#
|
191
|
+
# The +LOGIN+ and +CRAM-MD5+ mechanisms are still available for backwards
|
192
|
+
# compatibility, but are deprecated and should be avoided.
|
188
193
|
#
|
189
194
|
class SMTP < Protocol
|
190
|
-
VERSION = "0.
|
195
|
+
VERSION = "0.5.0"
|
191
196
|
|
192
197
|
# The default SMTP port number, 25.
|
193
198
|
def SMTP.default_port
|
@@ -229,10 +234,13 @@ module Net
|
|
229
234
|
# If the hostname in the server certificate is different from +address+,
|
230
235
|
# it can be specified with +tls_hostname+.
|
231
236
|
#
|
232
|
-
# Additional SSLContext
|
233
|
-
# +
|
237
|
+
# Additional SSLContext[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html]
|
238
|
+
# params can be added to the +ssl_context_params+ hash argument and are
|
239
|
+
# passed to {OpenSSL::SSL::SSLContext#set_params}[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html#method-i-set_params].
|
240
|
+
#
|
241
|
+
# <tt>tls_verify: true</tt> is equivalent to <tt>ssl_context_params: {
|
242
|
+
# verify_mode: OpenSSL::SSL::VERIFY_PEER }</tt>.
|
234
243
|
#
|
235
|
-
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
|
236
244
|
# This method does not open the TCP connection. You can use
|
237
245
|
# SMTP.start instead of SMTP.new if you want to do everything
|
238
246
|
# at once. Otherwise, follow SMTP.new with SMTP#start.
|
@@ -316,12 +324,13 @@ module Net
|
|
316
324
|
auth_capable?('CRAM-MD5')
|
317
325
|
end
|
318
326
|
|
327
|
+
# Returns whether the server advertises support for the authentication type.
|
328
|
+
# You cannot get valid result before opening SMTP session.
|
319
329
|
def auth_capable?(type)
|
320
330
|
return nil unless @capabilities
|
321
331
|
return false unless @capabilities['AUTH']
|
322
332
|
@capabilities['AUTH'].include?(type)
|
323
333
|
end
|
324
|
-
private :auth_capable?
|
325
334
|
|
326
335
|
# Returns supported authentication methods on this server.
|
327
336
|
# You cannot get valid value before opening SMTP session.
|
@@ -338,7 +347,7 @@ module Net
|
|
338
347
|
|
339
348
|
alias ssl? tls?
|
340
349
|
|
341
|
-
# Enables SMTP/TLS (SMTPS: SMTP over direct TLS connection) for
|
350
|
+
# Enables SMTP/TLS (SMTPS: \SMTP over direct TLS connection) for
|
342
351
|
# this object. Must be called before the connection is established
|
343
352
|
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
|
344
353
|
def enable_tls(context = nil)
|
@@ -457,7 +466,10 @@ module Net
|
|
457
466
|
#
|
458
467
|
# This method is equivalent to:
|
459
468
|
#
|
460
|
-
# Net::SMTP.new(address, port
|
469
|
+
# Net::SMTP.new(address, port, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
|
470
|
+
# .start(helo: helo_domain, user: account, secret: password, authtype: authtype)
|
471
|
+
#
|
472
|
+
# See also: Net::SMTP.new, #start
|
461
473
|
#
|
462
474
|
# === Example
|
463
475
|
#
|
@@ -482,12 +494,6 @@ module Net
|
|
482
494
|
# +helo+ is the _HELO_ _domain_ provided by the client to the
|
483
495
|
# server (see overview comments); it defaults to 'localhost'.
|
484
496
|
#
|
485
|
-
# The remaining arguments are used for SMTP authentication, if required
|
486
|
-
# or desired. +user+ is the account name; +secret+ is your password
|
487
|
-
# or other authentication token; and +authtype+ is the authentication
|
488
|
-
# type, one of :plain, :login, or :cram_md5. See the discussion of
|
489
|
-
# SMTP Authentication in the overview notes.
|
490
|
-
#
|
491
497
|
# If +tls+ is true, enable TLS. The default is false.
|
492
498
|
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
|
493
499
|
# if false, disable STARTTLS.
|
@@ -496,10 +502,26 @@ module Net
|
|
496
502
|
# If the hostname in the server certificate is different from +address+,
|
497
503
|
# it can be specified with +tls_hostname+.
|
498
504
|
#
|
499
|
-
# Additional SSLContext
|
500
|
-
# +
|
505
|
+
# Additional SSLContext[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html]
|
506
|
+
# params can be added to the +ssl_context_params+ hash argument and are
|
507
|
+
# passed to {OpenSSL::SSL::SSLContext#set_params}[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html#method-i-set_params].
|
501
508
|
#
|
502
|
-
#
|
509
|
+
# <tt>tls_verify: true</tt> is equivalent to <tt>ssl_context_params: {
|
510
|
+
# verify_mode: OpenSSL::SSL::VERIFY_PEER }</tt>.
|
511
|
+
#
|
512
|
+
# The remaining arguments are used for \SMTP authentication, if required or
|
513
|
+
# desired.
|
514
|
+
#
|
515
|
+
# +authtype+ is the SASL authentication mechanism.
|
516
|
+
#
|
517
|
+
# +user+ is the authentication or authorization identity.
|
518
|
+
#
|
519
|
+
# +secret+ or +password+ is your password or other authentication token.
|
520
|
+
#
|
521
|
+
# These will be sent to #authenticate as positional arguments-the exact
|
522
|
+
# semantics are dependent on the +authtype+.
|
523
|
+
#
|
524
|
+
# See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
|
503
525
|
#
|
504
526
|
# === Errors
|
505
527
|
#
|
@@ -527,7 +549,7 @@ module Net
|
|
527
549
|
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)
|
528
550
|
end
|
529
551
|
|
530
|
-
# +true+ if the SMTP session has been started.
|
552
|
+
# +true+ if the \SMTP session has been started.
|
531
553
|
def started?
|
532
554
|
@started
|
533
555
|
end
|
@@ -544,11 +566,21 @@ module Net
|
|
544
566
|
# +helo+ is the _HELO_ _domain_ that you'll dispatch mails from; see
|
545
567
|
# the discussion in the overview notes.
|
546
568
|
#
|
547
|
-
#
|
548
|
-
#
|
549
|
-
#
|
550
|
-
#
|
551
|
-
#
|
569
|
+
# The remaining arguments are used for \SMTP authentication, if required or
|
570
|
+
# desired.
|
571
|
+
#
|
572
|
+
# +authtype+ is the SASL authentication mechanism.
|
573
|
+
#
|
574
|
+
# +user+ is the authentication or authorization identity.
|
575
|
+
#
|
576
|
+
# +secret+ or +password+ is your password or other authentication token.
|
577
|
+
#
|
578
|
+
# These will be sent to #authenticate as positional arguments-the exact
|
579
|
+
# semantics are dependent on the +authtype+.
|
580
|
+
#
|
581
|
+
# See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
|
582
|
+
#
|
583
|
+
# See also: Net::SMTP.start
|
552
584
|
#
|
553
585
|
# === Block Usage
|
554
586
|
#
|
@@ -633,9 +665,8 @@ module Net
|
|
633
665
|
|
634
666
|
def do_start(helo_domain, user, secret, authtype)
|
635
667
|
raise IOError, 'SMTP session already started' if @started
|
636
|
-
if user
|
637
|
-
|
638
|
-
check_auth_args user, secret
|
668
|
+
if user || secret || authtype
|
669
|
+
check_auth_args authtype, user, secret
|
639
670
|
end
|
640
671
|
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
|
641
672
|
tcp_socket(@address, @port)
|
@@ -831,32 +862,26 @@ module Net
|
|
831
862
|
|
832
863
|
DEFAULT_AUTH_TYPE = :plain
|
833
864
|
|
865
|
+
# Authenticates with the server, using the "AUTH" command.
|
866
|
+
#
|
867
|
+
# +authtype+ is the name of a SASL authentication mechanism.
|
868
|
+
#
|
869
|
+
# All arguments-other than +authtype+-are forwarded to the authenticator.
|
870
|
+
# Different authenticators may interpret the +user+ and +secret+
|
871
|
+
# arguments differently.
|
834
872
|
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
|
835
|
-
|
836
|
-
check_auth_args user, secret
|
873
|
+
check_auth_args authtype, user, secret
|
837
874
|
authenticator = Authenticator.auth_class(authtype).new(self)
|
838
875
|
authenticator.auth(user, secret)
|
839
876
|
end
|
840
877
|
|
841
878
|
private
|
842
879
|
|
843
|
-
def
|
844
|
-
|
880
|
+
def check_auth_args(type, *args, **kwargs)
|
881
|
+
type ||= DEFAULT_AUTH_TYPE
|
882
|
+
klass = Authenticator.auth_class(type) or
|
845
883
|
raise ArgumentError, "wrong authentication type #{type}"
|
846
|
-
|
847
|
-
end
|
848
|
-
|
849
|
-
def auth_method(type)
|
850
|
-
"auth_#{type.to_s.downcase}".intern
|
851
|
-
end
|
852
|
-
|
853
|
-
def check_auth_args(user, secret, authtype = DEFAULT_AUTH_TYPE)
|
854
|
-
unless user
|
855
|
-
raise ArgumentError, 'SMTP-AUTH requested but missing user name'
|
856
|
-
end
|
857
|
-
unless secret
|
858
|
-
raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
|
859
|
-
end
|
884
|
+
klass.check_args(*args, **kwargs)
|
860
885
|
end
|
861
886
|
|
862
887
|
#
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-protocol
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/net/smtp/auth_cram_md5.rb
|
39
39
|
- lib/net/smtp/auth_login.rb
|
40
40
|
- lib/net/smtp/auth_plain.rb
|
41
|
+
- lib/net/smtp/auth_xoauth2.rb
|
41
42
|
- lib/net/smtp/authenticator.rb
|
42
43
|
homepage: https://github.com/ruby/net-smtp
|
43
44
|
licenses:
|
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
- !ruby/object:Gem::Version
|
62
63
|
version: '0'
|
63
64
|
requirements: []
|
64
|
-
rubygems_version: 3.5.
|
65
|
+
rubygems_version: 3.5.3
|
65
66
|
signing_key:
|
66
67
|
specification_version: 4
|
67
68
|
summary: Simple Mail Transfer Protocol client library for Ruby.
|