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

Mailer timeout #35138

Closed
seddighi78 opened this issue Dec 29, 2019 · 12 comments
Closed

Mailer timeout #35138

seddighi78 opened this issue Dec 29, 2019 · 12 comments

Comments

@seddighi78
Copy link

Symfony version(s) affected: 4.4.2

Description
I'm using Mailer component for send email in Symfony and set env variables for MAILER_DSN

 MAILER_USERNAME=mailer@example.con
 MAILER_PASSWORD=**************
 MAILER_DSN=smtp://$MAILER_USERNAME:$MAILER_PASSWORD@mail.example.com:465

the emails was send but throw error for timeout:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Mailer\Exception\TransportException: "Connection to "ssl://mail.example.com:465" timed out." at path/path/vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php line 81 {"exception":"[object] (Symfony\Component\Mailer\Exception\TransportException(code: 0): Connection to \"ssl://mail.grandsocial.net:465\" timed out. at path/path/vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php:81)"} []

i think this is bug or if not please help to solve this.
thanks

@michaljusiega
Copy link
Contributor

This is not bug. The timeout is default 5 second defined in:
SocketStream::$timeout = 5;

There is no configuration here to set this time nor any setter. Increase value anyway.

@michaljusiega
Copy link
Contributor

@seddighi78 can you confirm temporary solution ?

@seddighi78
Copy link
Author

@michaljusiega I'm using a try-catch to control the throws of the mailer. the mail was successfully sent but time out happened.

@michaljusiega
Copy link
Contributor

Yes because your SMTP server probably analyze your mail too slowly so you got a exception for this reason.

@seddighi78
Copy link
Author

Do I have to wait for this problem or is there a right solution?

@azjezz
Copy link
Contributor

azjezz commented Jan 3, 2020

@seddighi78 this is not a bug, as @michaljusiega has mentioned, your server is taking too long to responed and symfony mailer is timing out.

if you want to increase the timeout, you can do so using :

$transport->getStream()->setTimeout($timeoutInSeconds);

@seddighi78
Copy link
Author

seddighi78 commented Jan 3, 2020

@azjezz How can i change timeout from event listener or controller? I can't change timeout from configuration

@fabpot
Copy link
Member

fabpot commented Jan 28, 2020

I would highly recommend to fix the latency of the server if possible. If not, configure default_socket_timeout in the php.ini file (which will be available for SMTP server as of Symfony 5.1). In the meantime, using the snippet given by @azjezz will work as well.

@fabpot fabpot closed this as completed Jan 28, 2020
fabpot added a commit that referenced this issue Jan 28, 2020
…(azjezz)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Mailer] read default timeout from ini configurations

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #35138
| License       | MIT
| Doc PR        | n/a

```env
MAILER_DSN=mandrill+https://foo@default?timeout=30
```

Commits
-------

dafb057 [Mailer] read default timeout from ini configurations
@michaljusiega
Copy link
Contributor

Thank you @fabpot

@leonelvsc
Copy link

The only way of solving this in 4.4 is creating a custom factory that configures the timeout of the socket ?

@apphancer
Copy link

Here's my problem with this: Application is running on Symfony 5.0 and files between 3-4 MB need to get attached. In the development environment, we are using Mailhog on a Docker container - the former being notoriously slow at processing emails with attachments. In this scenario, we are getting a ["/app/vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php","Connection to "localhost:1025" timed out."] error from our Console command. Emails are still being sent and received successfully.
default_socket_timeout is set to 60 in the ini settings used by PHP CLI, but this seems to be ignored.

@karser
Copy link
Contributor

karser commented Aug 24, 2021

I solved it for v4.4 by setting timeout in the decorated EsmtpTransportFactory::create method.
I blogged about it.

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

No branches or pull requests

9 participants