Skip to content

Commit 2cfc961

Browse files
committed
Updated docs, especially TLS and SASL-related
* Escaped SMTP in many places where it refers to the protocol, not the class. * Fixed some ruby example syntax, so rdoc syntax highlighting works. * Separated `SMTP.start or SMTP#start`, so rdoc can link both methods. * Updated the RFC links. Fixed link to RFC6409 (not 6503!). * Linked to the `mail` (previously TMail) and `rmail` (previously RubyMail) gems. * Fixed `<tt>` formatting issues. * "See also" links from `start` methods. * Removed detailed documentation for deprecated `LOGIN` and `CRAM-MD5`. * Clarified authentication arg docs to Net::SMTP.start and #start. * Linked directly to Net::SMTP@SMTP+Authentication.
1 parent c41e299 commit 2cfc961

File tree

1 file changed

+89
-48
lines changed

1 file changed

+89
-48
lines changed

lib/net/smtp.rb

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,34 @@ class SMTPUnsupportedCommand < ProtocolError
7979
# == What is This Library?
8080
#
8181
# 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
8585
# 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
8989
# necessary to send messages to/from addresses containing characters
9090
# outside the ASCII range.
9191
#
9292
# == What is This Library NOT?
9393
#
9494
# This library does NOT provide functions to compose internet mails.
9595
# 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
9798
# {RubyGems.org}[https://rubygems.org/] or {The Ruby
9899
# Toolbox}[https://www.ruby-toolbox.com/].
99100
#
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]].
101103
#
102104
# == Examples
103105
#
104106
# === Sending Messages
105107
#
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
108110
# argument is the port number. Using SMTP.start with a block is the simplest
109111
# way to do this. This way, the SMTP connection is closed automatically
110112
# after the block is executed.
@@ -114,7 +116,7 @@ class SMTPUnsupportedCommand < ProtocolError
114116
# # Use the SMTP object smtp only in this block.
115117
# end
116118
#
117-
# Replace 'your.smtp.server' with your SMTP server. Normally
119+
# Replace 'your.smtp.server' with your \SMTP server. Normally
118120
# your system manager or internet provider supplies a server
119121
# for you.
120122
#
@@ -147,7 +149,7 @@ class SMTPUnsupportedCommand < ProtocolError
147149
# smtp.send_message msgstr, 'from@address', 'to@address'
148150
# smtp.finish
149151
#
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
151153
# the SMTP session automatically:
152154
#
153155
# # using block form of SMTP.start
@@ -160,31 +162,34 @@ class SMTPUnsupportedCommand < ProtocolError
160162
# === HELO domain
161163
#
162164
# 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
164166
# (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
166168
# the SMTP session by inspecting the HELO domain.
167169
#
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
170175
#
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)_.
172180
#
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.
177183
#
178184
# # PLAIN
179-
# Net::SMTP.start('your.smtp.server', 25
185+
# Net::SMTP.start('your.smtp.server', 25,
180186
# 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)
184187
#
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.
188193
#
189194
class SMTP < Protocol
190195
VERSION = "0.4.0"
@@ -229,10 +234,13 @@ def SMTP.default_ssl_context(ssl_context_params = nil)
229234
# If the hostname in the server certificate is different from +address+,
230235
# it can be specified with +tls_hostname+.
231236
#
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>.
234243
#
235-
# +tls_verify: true+ is equivalent to +ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }+.
236244
# This method does not open the TCP connection. You can use
237245
# SMTP.start instead of SMTP.new if you want to do everything
238246
# at once. Otherwise, follow SMTP.new with SMTP#start.
@@ -338,7 +346,7 @@ def tls?
338346

339347
alias ssl? tls?
340348

341-
# Enables SMTP/TLS (SMTPS: SMTP over direct TLS connection) for
349+
# Enables SMTP/TLS (SMTPS: \SMTP over direct TLS connection) for
342350
# this object. Must be called before the connection is established
343351
# to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
344352
def enable_tls(context = nil)
@@ -457,7 +465,10 @@ def debug_output=(arg)
457465
#
458466
# This method is equivalent to:
459467
#
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
461472
#
462473
# === Example
463474
#
@@ -482,12 +493,6 @@ def debug_output=(arg)
482493
# +helo+ is the _HELO_ _domain_ provided by the client to the
483494
# server (see overview comments); it defaults to 'localhost'.
484495
#
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-
#
491496
# If +tls+ is true, enable TLS. The default is false.
492497
# If +starttls+ is :always, enable STARTTLS, if +:auto+, use STARTTLS when the server supports it,
493498
# if false, disable STARTTLS.
@@ -496,10 +501,26 @@ def debug_output=(arg)
496501
# If the hostname in the server certificate is different from +address+,
497502
# it can be specified with +tls_hostname+.
498503
#
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.
501517
#
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.
503524
#
504525
# === Errors
505526
#
@@ -527,7 +548,7 @@ def SMTP.start(address, port = nil, *args, helo: nil,
527548
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)
528549
end
529550

530-
# +true+ if the SMTP session has been started.
551+
# +true+ if the \SMTP session has been started.
531552
def started?
532553
@started
533554
end
@@ -544,11 +565,21 @@ def started?
544565
# +helo+ is the _HELO_ _domain_ that you'll dispatch mails from; see
545566
# the discussion in the overview notes.
546567
#
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
552583
#
553584
# === Block Usage
554585
#
@@ -831,6 +862,16 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
831862

832863
DEFAULT_AUTH_TYPE = :plain
833864

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.
834875
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
835876
check_auth_method authtype
836877
check_auth_args user, secret

0 commit comments

Comments
 (0)