mrakodol
mrakodol

Reputation: 1243

Laravel 9 mail on production get only this error - Expected response code "250" but got code "451"

We've upgraded our application to Laravel 9 last week and noticed a large amount of failed jobs appearing as soon as we deployed the build in production.

Those errors were all email related with the following error message:

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

We've reverted back to the previous build (which was using SwiftMailer) and the errors stopped. To clarify, we've been running the application for a few weeks and never had that error before.

On "Staging" we didn't have that issue. The only difference is we use SQS for queues in live and set :

APP_ENV=production
APP_DEBUG=false

that are the only differences.

Upvotes: 8

Views: 4599

Answers (2)

niranjan
niranjan

Reputation: 19

As suggested in the above answer https://stackoverflow.com/a/71530024/16046216, setting 'ping_threshold' => 10 in config/mail.php works for me.

However, do NOT add it to mailers configuration for smtp or ses. Add this at the root level (same level at which mailers or log_channel are added) in the configuration file. Refer to below snapshot of config/mail.php configuration in Laravel project:

<?php

return [
    ...
    /*
    |--------------------------------------------------------------------------
    | Mailer Configurations
    |--------------------------------------------------------------------------
    |
    */

    'mailers' => [
        'smtp' = [
            ...
        ],
        ...
    ],

    ...

    /*
    |--------------------------------------------------------------------------
    | Transport Settings
    |--------------------------------------------------------------------------
    |
    */
    'ping_threshold' => 10,
];

After debugging I found how the configuration options are read and setup in \Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory and \Illuminate\Mail\MailManager::createSmtpTransport().

We were getting this error on production servers very frequently after upgrading to Laravel 9.x from 8.x. On the server, the emails are being sent through SES using the background queue (SQS) service.

Upvotes: 1

MrCarrot
MrCarrot

Reputation: 2778

Could you try adding 'ping_threshold' => 10, to your smtp or ses configuration in config/mail.php

If you are using a queue worker/manager, remember to restart the process for the new configuration to come into effect.

This seems to have resolved the issue for me. Could be coincidental, but will report back if the issue returns.

Upvotes: 16

Related Questions