Search code examples
symfony1swiftmailer

Symfony mailer: Swift_TransportException between message sending


On a current project which I'm currently working, i have a symfony task that runs some mass data insertion to database and runs it for at least half an hour. When the task starts a mail notification is sent correctly, the problem is that at the of the task execution we can't send another mail to notify about the end of processing.

The mailer factory is currently configured with the spool delivery strategy but, in this specific situation, we desire to fire a notification immediately, using the sendNextImmediately() method.

I'm are getting the exception:

[Swift_TransportException]
Expected response code 250 but got code "451", with message "451 4.4.2 Timeout - closing connection. 74sm1186065wem.17 "

and the flowing error on php log file:

Warning: fwrite(): SSL: Broken pipe in /var/www/project/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php on line 209

Can anyone give some help? Is there any way that i can perhaps refresh symfony mailer to establish a new connection?


Solution

  • For Symfony1 Users

    My guess was that the connection was being hold for too long (with no activity at all), causing an ssl connection timeout.

    For now, the problem can be solved by stopping the Swift_Transport instance and starting it again explicitly, just before sending the second message.

    Here is the code:

    $this->getMailer()->getRealtimeTransport()->stop();
    $this->getMailer()->getRealtimeTransport()->start();
    $this->getMailer()->sendNextImmediately()->send($message);