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

Cannot set TLS for email on port other than 465 #45899

Closed
leinelissen opened this issue Feb 1, 2023 · 2 comments
Closed

Cannot set TLS for email on port other than 465 #45899

leinelissen opened this issue Feb 1, 2023 · 2 comments

Comments

@leinelissen
Copy link

leinelissen commented Feb 1, 2023

  • Laravel Version: 9.23.0
  • PHP Version: 8.1.9
  • Database Driver & Version: Postgres 14.4

Description:

At the beginning of last year, someone was unable to connect to an email server (#40887). I cannot really follow what the underlying problem eventually is, but a pull request (#40943) is made that fixes the issue and everything is closed.

The problem is that in that PR, the configuration is locked down the smtps scheme for Symfony Mailer is only set in case MAIL_ENCRYPTION is set to tls and MAIL_PORT is set to 465. The problem is that if you would like to connect to a SMTP server via TLS directly on a port other than 465, there is no way to configure this.

My hunch is that somewhere along the way TLS and STARTTLS got confused. As a recap (per Mailtrap), TLS means that the whole SMTP connection is encapsulated in TLS. This is often called SMTPS. Whereas with STARTTLS, the connection will start as a regular SMTP connection and get upgraded to TLS during the handshake.

The scheme Symfony Mailer refers to determines the TLS status, so smtps is used for SMTP over TLS, where as smtp is used for plain SMTP, with a potential upgrade using STARTTLS. The extra confusing thing is that Symfony Mailer deprecated explicit STARTTLS options in version 4.4, meaning that from this version onwards it will automatically upgrade a connection with STARTTLS if it is available.

I would like to make it possible to use SMTPS for ports other than 465. This is a valid use case since some cloud providers block common SMTP ports (20, 465, 587) and thus offer alternative ports (e.g. Scaleway offers SMTP over TLS on port 2465.

Hence, I propose to revert PR #40943 and will submit a PR soon for doing so soon. Using STARTTLS was already perfectly possible before the PR, but this meant users had to set MAIL_ENCRYPTION to null. I get that this is counter-intuitive, so maybe it is a good idea to add some docs and/or consider dropping MAIL_ENCRYPTION so developers know how to deal with this.

Pinging @driesvints and @nicolalazzaro since you were involved with the mentioned issue and PR.

Steps To Reproduce:

Create a new Laravel application, and attempt to send out an email to a TLS SMTP-server on a port other than 465 (e.g. 2465). The connection will time-out and the following error will be thrown:

Symfony\Component\Mailer\Exception\TransportException with message 'Connection could not be established with host "server:2465": stream_socket_client(): Unable to connect to server:2465 (Operation timed out)'
@leinelissen
Copy link
Author

Slight addition: I noticed some speak that TLS was hard-locked to port 465 in the other issue. I have just tested a branch which reverts the PR and it is perfectly possible to send email over TLS using a non-465 port, so I feel this shouldn't be a blocker.

leinelissen added a commit to leinelissen/framework that referenced this issue Feb 1, 2023
leinelissen added a commit to leinelissen/framework that referenced this issue Feb 1, 2023
@leinelissen
Copy link
Author

Fixed per 68a8bfc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant