@@ -79,32 +79,34 @@ class SMTPUnsupportedCommand < ProtocolError
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] (http ://www.ietf .org/rfc/rfc5321.txt) .
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](http ://www.ietf .org/rfc/rfc6503.txt) ,
88
- # and [SMTPUTF8](http ://www.ietf .org/rfc/rfc6531.txt) , which is
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
#
92
92
# == What is This Library NOT?
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 RubyMail or TMail or search for alternatives in
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: [RFC5322] (http://www.ietf.org/rfc/rfc5322.txt).
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 @@ class SMTPUnsupportedCommand < ProtocolError
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 @@ class SMTPUnsupportedCommand < ProtocolError
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/ SMTP#start. This closes
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,31 +162,34 @@ class SMTPUnsupportedCommand < ProtocolError
160
162
# === HELO domain
161
163
#
162
164
# In almost all situations, you must provide a third argument
163
- # to SMTP.start/ SMTP#start. This is the domain name which you are on
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
- # helo: 'mail.from.domain') { |smtp| ... }
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
173
+ #
174
+ # === \SMTP Authentication
170
175
#
171
- # === SMTP Authentication
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)_.
172
180
#
173
- # The Net::SMTP class supports three authentication schemes;
174
- # PLAIN, LOGIN and CRAM MD5. (SMTP Authentication: [RFC2554])
175
- # To use SMTP authentication, pass extra arguments to
176
- # SMTP.start/SMTP#start.
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
- # # CRAM MD5
186
- # Net::SMTP.start('your.smtp.server', 25
187
- # user: 'Your Account', secret: 'Your Password', authtype: :cram_md5)
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
195
VERSION = "0.4.0"
@@ -229,10 +234,13 @@ def SMTP.default_ssl_context(ssl_context_params = nil)
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 params can be added to +ssl_context_params+ hash argument and are passed to
233
- # +OpenSSL::SSL::SSLContext#set_params+
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.
@@ -338,7 +346,7 @@ def tls?
338
346
339
347
alias ssl? tls?
340
348
341
- # Enables SMTP/TLS (SMTPS: SMTP over direct TLS connection) for
349
+ # Enables SMTP/TLS (SMTPS: \ SMTP over direct TLS connection) for
342
350
# this object. Must be called before the connection is established
343
351
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
344
352
def enable_tls ( context = nil )
@@ -457,7 +465,10 @@ def debug_output=(arg)
457
465
#
458
466
# This method is equivalent to:
459
467
#
460
- # 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)
468
+ # Net::SMTP.new(address, port, tls_verify: flag, tls_hostname: hostname, ssl_context_params: nil)
469
+ # .start(helo: helo_domain, user: account, secret: password, authtype: authtype)
470
+ #
471
+ # See also: Net::SMTP.new, #start
461
472
#
462
473
# === Example
463
474
#
@@ -482,12 +493,6 @@ def debug_output=(arg)
482
493
# +helo+ is the _HELO_ _domain_ provided by the client to the
483
494
# server (see overview comments); it defaults to 'localhost'.
484
495
#
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
496
# If +tls+ is true, enable TLS. The default is false.
492
497
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
493
498
# if false, disable STARTTLS.
@@ -496,10 +501,26 @@ def debug_output=(arg)
496
501
# If the hostname in the server certificate is different from +address+,
497
502
# it can be specified with +tls_hostname+.
498
503
#
499
- # Additional SSLContext params can be added to +ssl_context_params+ hash argument and are passed to
500
- # +OpenSSL::SSL::SSLContext#set_params+
504
+ # Additional SSLContext[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html]
505
+ # params can be added to the +ssl_context_params+ hash argument and are
506
+ # passed to {OpenSSL::SSL::SSLContext#set_params}[https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html#method-i-set_params].
507
+ #
508
+ # <tt>tls_verify: true</tt> is equivalent to <tt>ssl_context_params: {
509
+ # verify_mode: OpenSSL::SSL::VERIFY_PEER }</tt>.
510
+ #
511
+ # The remaining arguments are used for \SMTP authentication, if required or
512
+ # desired.
513
+ #
514
+ # +authtype+ is the SASL authentication mechanism.
515
+ #
516
+ # +user+ is the authentication or authorization identity.
501
517
#
502
- # +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
518
+ # +secret+ or +password+ is your password or other authentication token.
519
+ #
520
+ # These will be sent to #authenticate as positional arguments—the exact
521
+ # semantics are dependent on the +authtype+.
522
+ #
523
+ # See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
503
524
#
504
525
# === Errors
505
526
#
@@ -527,7 +548,7 @@ def SMTP.start(address, port = nil, *args, helo: nil,
527
548
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
549
end
529
550
530
- # +true+ if the SMTP session has been started.
551
+ # +true+ if the \ SMTP session has been started.
531
552
def started?
532
553
@started
533
554
end
@@ -544,11 +565,21 @@ def started?
544
565
# +helo+ is the _HELO_ _domain_ that you'll dispatch mails from; see
545
566
# the discussion in the overview notes.
546
567
#
547
- # If both of +user+ and +secret+ are given, SMTP authentication
548
- # will be attempted using the AUTH command. +authtype+ specifies
549
- # the type of authentication to attempt; it must be one of
550
- # :login, :plain, and :cram_md5. See the notes on SMTP Authentication
551
- # in the overview.
568
+ # The remaining arguments are used for \SMTP authentication, if required or
569
+ # desired.
570
+ #
571
+ # +authtype+ is the SASL authentication mechanism.
572
+ #
573
+ # +user+ is the authentication or authorization identity.
574
+ #
575
+ # +secret+ or +password+ is your password or other authentication token.
576
+ #
577
+ # These will be sent to #authenticate as positional arguments—the exact
578
+ # semantics are dependent on the +authtype+.
579
+ #
580
+ # See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
581
+ #
582
+ # See also: Net::SMTP.start
552
583
#
553
584
# === Block Usage
554
585
#
@@ -831,6 +862,16 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
831
862
832
863
DEFAULT_AUTH_TYPE = :plain
833
864
865
+ # call-seq:
866
+ # authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
867
+ #
868
+ # Authenticates with the server, using the "AUTH" command.
869
+ #
870
+ # +type+ is the name of a SASL authentication mechanism.
871
+ #
872
+ # All arguments—other than +type+—are forwarded to the authenticator.
873
+ # Different authenticators may interpret the +username+ and +secret+
874
+ # arguments differently.
834
875
def authenticate ( user , secret , authtype = DEFAULT_AUTH_TYPE )
835
876
check_auth_method authtype
836
877
check_auth_args user , secret
0 commit comments