[Mailer] Simplify the way TLS/SSL/STARTTLS work #33233
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The way TLS/SSL/STARTTLS is handled is not easy to understand. It's inherited from Swiftmailer and today, I've spent some time to see if we could improve it.
First, the current way:
setEncryption()
takes a string, eitherssl
ortls
:ssl
: to enable TLS support on the connectiontls
: to enableSTARTTLS
(upgrade the connection)There is also a
isTLS()
method which is really confusing due to the fact that both configuration are about TLS anyway.So, this PR changes things radically:
The
setEncryption
method and theencryption
option on the DSN are gone.TLS is used by default and you can disable it via
disableTls()
. Being secure by default is probably a good idea anyway (like using HTTPS by default instead of HTTP).A new "protocol" SMTPS is supported now and is a way to say that you want TLS; so use
smtps://localhost
to set TLS instead ofsmtp://localhost?encryption=ssl
. Note that usingsmtp://localhost:465
does the same. All third-party providers now supports bothsmtp
andsmtps
protocol even if that does the exact same thing for them (TLS is always enabled).The port is automatically determined based on the TLS setting (if not set explicitly). So 465 for TLS and falls back to 25.
There is no more way to enable
STARTTLS
. If you don't configure TLS on the connection and if the server supportsSTARTTLS
, then we will enable it automatically.Great document about all of this: https://www.fastmail.com/help/technical/ssltlsstarttls.html