Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document SMTP TLS/STARTTLS settings (cherry-picked from 2.8 stable branch) #1613

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/mail/network/delivery_methods/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Mail
# :user_name => '<username>',
# :password => '<password>',
# :authentication => 'plain',
# :enable_starttls_auto => true }
# :enable_starttls => :auto }
# end
#
# === Sending via GMail
Expand All @@ -34,9 +34,17 @@ module Mail
# :user_name => '<username>',
# :password => '<password>',
# :authentication => 'plain',
# :enable_starttls_auto => true }
# :enable_starttls => :auto }
# end
#
# === Configuring TLS/SSL and STARTTLS
#
# A few remarks:
# - 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.
# - 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`.
# - when providing a truthy value for `enable_starttls`, the `enable_starttls_auto`-flag will be ignored.
# - when none of `tls`, `ssl`, `enable_starttls` or `enable_starttls_auto` is set, the fallback will be `enable_starttls` `:auto`.
#
# === Certificate verification
#
# When using TLS, some mail servers provide certificates that are self-signed
Expand Down Expand Up @@ -112,6 +120,8 @@ def setting_provided?(k)

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

Expand All @@ -137,7 +147,7 @@ def smtp_starttls
end

def smtp_tls?
setting_provided?(:tls) && settings[:tls] || setting_provided?(:ssl) && settings[:ssl]
(setting_provided?(:tls) && settings[:tls]) || (setting_provided?(:ssl) && settings[:ssl])
end

def start_smtp_session(&block)
Expand Down
Loading