Skip to content

[Mailer] SMTP transport with AWS SES: "Timeout waiting for data from client" #39044

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

Closed
arjanfrans opened this issue Nov 10, 2020 · 2 comments · Fixed by #42219
Closed

[Mailer] SMTP transport with AWS SES: "Timeout waiting for data from client" #39044

arjanfrans opened this issue Nov 10, 2020 · 2 comments · Fixed by #42219

Comments

@arjanfrans
Copy link

arjanfrans commented Nov 10, 2020

Symfony version(s) affected: 4.4.16, 5.2

Description
Our system sends e-mails asynchronously using the Messenger component. Two messenger consumers are running in the background with Supervisor. We use Doctrine for our message transport and AWS SES over SMTP for e-mails. On our production system we are seeing the following error occur. This issue was already described here: #36301. A PR was merged, but we are still seeing this problem.

Symfony\Component\Mailer\Exception\TransportException

Expected response code "250" but got code "451", with message "451 4.4.2 Timeout waiting for data from client.".

After the messages fail for the first time, they will get retried. Eventually after one or two retries they do get send successfully.

How to reproduce
See #36301

@arjanfrans arjanfrans added the Bug label Nov 10, 2020
@arjanfrans arjanfrans changed the title [Mailer] SMPT transport with AWS SES: "Timeout waiting for data from client" [Mailer] SMTP transport with AWS SES: "Timeout waiting for data from client" Nov 10, 2020
@arjanfrans
Copy link
Author

I tried the $pingThreshold solution described here: #36301, setting the pingThreshold to 10 seconds. Unfortunately the problem still persists (maybe it will occur less, but it's too soon to tell).

// config/packages/mailer.yaml

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

services:
    mailer.transport_factory.smtp:
        class: App\Mail\Transport\EsmtpTransportFactory
        parent: mailer.transport_factory.abstract
        tags:
            - { name: mailer.transport_factory, priority: -100 }

// src/App/Mail/Transport/EsmtpTransportFactory.php

<?php

namespace App\Mail\Transport;

use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\TransportInterface;

class EsmtpTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $tls = 'smtps' === $dsn->getScheme() ? true : null;
        $port = $dsn->getPort(0);
        $host = $dsn->getHost();

        $transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
        $transport->setPingThreshold(10);

        if ($user = $dsn->getUser()) {
            $transport->setUsername($user);
        }

        if ($password = $dsn->getPassword()) {
            $transport->setPassword($password);
        }

        return $transport;
    }

    protected function getSupportedSchemes(): array
    {
        return ['smtp', 'smtps'];
    }
}

@xabbuh xabbuh added the Mailer label Nov 10, 2020
@anthony-bennett
Copy link

I know this is an old issue, but for what it's worth, we ran into the same problem using ses+smtps as the scheme. Since we were just using SMTP and not the API, we switched to using smtps instead, and added ping_threshold=10 to the DSN, which resolved the issue for us.

It looks like the SesTransportFactory doesn't handle the ping_threshold parameter, but EsmtpTransportFactory does.

If this is an SES specific issue, maybe setting the threshold should be done automatically in SesSmtpTransport?

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