5

I have some problems for a long time now.

My app is sending mails to the customers.
In last months I've migrated this app to the Laravel (5.4 currently).
Many times I am receiving error:

Swift_TransportException in AbstractSmtpTransport.php line 404:
Connection to my-smtp.company.com:25 Timed Out

Problem is that I cannot get rid of this error message.
It happen in about 10% of cases - or queued task and mails sent in realtime.
Strange is that those mails are send out in fact but error show up anyway.

I am using Windows server and for queued mails running listener this way:

D:\php-7.1.1-x64\php.exe D:\wwwroot\myapp\artisan queue:listen --timeout=60 --tries=1

I've made some tests and looks like when errors is throws it is always after 33-36 second after firing queue job or executing code in browser.

Changed max_execution_time time to the 60 seconds but that didn't helped.

Anyone can help me?

LuFFy
  • 8,799
  • 10
  • 41
  • 59
Grzesiek
  • 442
  • 4
  • 15
  • Possible duplicate of [Swift\_TransportException in AbstractSmtpTransport.php line 404: Connection to smtp.gmail.com:465 Timed Out](http://stackoverflow.com/questions/33630220/swift-transportexception-in-abstractsmtptransport-php-line-404-connection-to-sm) – LuFFy Feb 21 '17 at 11:28
  • No, it's not. In my case it is working but giving timeout errors while sending mails successfully. – Grzesiek Feb 21 '17 at 11:42
  • Try following Solution : http://stackoverflow.com/a/38197222/2087247 – LuFFy Feb 21 '17 at 12:15
  • 2
    I do not have a problem with connection. This is not my first app in Laravel. I can connect successfully and sent hundreds of mails already. I have a problem with random timeout errors. Looks like it is somehow connected with swiftmailer which do not receive response from server. Maybe it is possible to change that timeout somehow... – Grzesiek Feb 21 '17 at 12:47
  • Same problem I am also facing with laravel 5.6. – Rohan Khude Aug 21 '18 at 09:47

1 Answers1

1

I have the same problem, and my app running on Laravel 6.0

My solution:

1) create a custom mail service provider.

2) use SwiftTransport method "setTimeout".

<?php

namespace App\Providers;

use Illuminate\Mail\MailServiceProvider as MailProvider;
use Illuminate\Mail\TransportManager;

class MailServiceProvider extends MailProvider
{
    /**
     * Register the Swift Transport instance.
     *
     * @return void
     */
    protected function registerSwiftTransport()
    {
        $this->app->singleton('swift.transport', function ($app) {
            $transport = new TransportManager($app);
            $transport->setTimeout(config('mail.connection_timeout'));
            return $transport;
        });
    }

}

3) replace provider config in \config\app.php

'provider' => [
...
// Illuminate\Mail\MailServiceProvider::class,
App\Providers\MailServiceProvider::class,
...
],
IISU
  • 11
  • 1