-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Connection could not be established with host smtp and a different port from 465 with tls enabled #40887
Comments
@nicolalazzaro how did you solve this? |
I'm working on it, it's a problem with the certificate of authority for my machine. |
@nicolalazzaro please, if you solve this issue, report it here. |
I can confirm this happens to me too. |
I'll have a look tomorrow. |
Comparing the arguments of the vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php class. In the class vendor/symfony/mailer/Transport/Smtp/EsmtpTransport.php starting on line 48 there is a piece of code that may be useful in solving the problem. With port 465 and the argument "SocketStream->$tls" set to true the host in my case becomes "ssl://smtp.gmail.com:465" and the connection is successful, so the email is sent correctly. Laravel
Blank project
Here is a similar case history of the error and useful information: symfony/symfony#34846 (comment) |
Can everyone confirm they have their ports/SSL settings set correctly? |
I have this: 'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
], I attempted ports |
Does sending the email work if you set the MAIL_ENCRYPTION option to null? |
@nicolalazzaro seems that does it for me. |
I'm going to close this as there's an easy fix to the problem. We don't document port 2525 anywhere anymore it seems. I see the default settings from Mailtrap are incorrect as they recommend setting encryption to tls for port 2525. I suggest you contact them to fix that. Thanks all. |
This was not the case in the past, in fact if you copy the configuration from mailtrap it suggests that you set "tls" in the MAIL_ENCRYPTION option. I think the problem lies in the interfacing with the new symfony library. In @fabpot's comment below there should be the reason. |
This seems wrong to me |
If you use the symfony/mailer package, SocketStream class added the prefix "ssl//:" to the host only with port 465, otherwise it is not added and the "tls" connection uses "starttls". When using a different port it is not enabled to use the "ssl/:" prefix on the host. This is what I was able to figure out. |
Yeah this seems like a change in behavior in Symfony Mailer to me. We'd welcome PR's to add something to the upgrade guide 👍 |
@driesvints In Laravel 9 if you dump $this->stream->isTLS() in the first line before vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:252 you will always get true, even if the port is different from 465. If you create an empty project and install the symfony/mailer package this does not happen, if the port is different from 465 then $this->stream->isTLS() returns false. Around here should be the problem, unfortunately I'm in the office now and have no way of investigating. |
@nicolalazzaro hmm odd. Would be happy to see what your findings are here... |
…rt from 465 with tls enabled laravel#40887 Resolve this issue: laravel#40887
@driesvints this solves the problem, take a look #40943 |
Port 465 should work correctly though, have you tried using the package "symfony/mailer" outside of laravel and testing sending the email? Otherwise it is a problem related to the configuration of your machine, you can also try gmail smtp which allows you to connect with port 465. |
…rt from 465 with tls enabled #40887 (#40943) Resolve this issue: laravel/framework#40887
Description:
I have created a new application and receive the following linked error when sending an email.
With the same smtp parameters the error does not occur on the same machine but with laravel version 8.83.0.
I then created a new project using the new library "symfony/mailer" but the sending of the email is successful.
Flare error url: https://flareapp.io/share/B5ZYQWg7#F55.
The text was updated successfully, but these errors were encountered: