Skip to content

Commit d419a9e

Browse files
authored
Merge pull request #1613 from nevans/copy-2.8-smtp-delivery-documentation
Document SMTP TLS/STARTTLS settings (cherry-picked from 2.8 stable branch)
2 parents 1fe6b59 + 0b029a3 commit d419a9e

File tree

1 file changed

+13
-3
lines changed
  • lib/mail/network/delivery_methods

1 file changed

+13
-3
lines changed

lib/mail/network/delivery_methods/smtp.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Mail
2222
# :user_name => '<username>',
2323
# :password => '<password>',
2424
# :authentication => 'plain',
25-
# :enable_starttls_auto => true }
25+
# :enable_starttls => :auto }
2626
# end
2727
#
2828
# === Sending via GMail
@@ -34,9 +34,17 @@ module Mail
3434
# :user_name => '<username>',
3535
# :password => '<password>',
3636
# :authentication => 'plain',
37-
# :enable_starttls_auto => true }
37+
# :enable_starttls => :auto }
3838
# end
3939
#
40+
# === Configuring TLS/SSL and STARTTLS
41+
#
42+
# A few remarks:
43+
# - when enabling `tls` (or `ssl`), setting (truthy values for) either `enable_starttls` or `enable_starttls_auto` will raise an ArgumentError as TLS and STARTTLS are mutually exclusive.
44+
# - to configure STARTTLS, use the `enable_starttls`-flag (instead of a combination of `enable_starttls` and `enable_starttls_auto`). Acceptable values are `:always`, `:auto` and `false`.
45+
# - when providing a truthy value for `enable_starttls`, the `enable_starttls_auto`-flag will be ignored.
46+
# - when none of `tls`, `ssl`, `enable_starttls` or `enable_starttls_auto` is set, the fallback will be `enable_starttls` `:auto`.
47+
#
4048
# === Certificate verification
4149
#
4250
# When using TLS, some mail servers provide certificates that are self-signed
@@ -112,6 +120,8 @@ def setting_provided?(k)
112120

113121
# Yields one of `:always`, `:auto` or `false` based on `enable_starttls` and `enable_starttls_auto` flags.
114122
# Yields `false` when `smtp_tls?`.
123+
# Else defaults to `:auto` when neither `enable_starttls*` flag is provided.
124+
# Providing a truthy value for `enable_starttls` will ignore `enable_starttls_auto`.
115125
def smtp_starttls
116126
return false if smtp_tls?
117127

@@ -137,7 +147,7 @@ def smtp_starttls
137147
end
138148

139149
def smtp_tls?
140-
setting_provided?(:tls) && settings[:tls] || setting_provided?(:ssl) && settings[:ssl]
150+
(setting_provided?(:tls) && settings[:tls]) || (setting_provided?(:ssl) && settings[:ssl])
141151
end
142152

143153
def start_smtp_session(&block)

0 commit comments

Comments
 (0)