I use SwiftMailer to send emails from a gearman worker process. I\'m using the Swift_SmtpTransport
class to send emails.
The problem is that if this wor
When pipe is broken $mailer->getTransport()->stop() will fail as well. And due to this error transport cannot be stopped. The workaround is
// Let's try to send an email.
$tries = 3;
while ($tries--) {
try {
$sent = $this->mailer->send($message);
break;
} catch (\Exception $e) {
// Connection problems
// @see https://github.com/swiftmailer/swiftmailer/issues/490
try {
// Try to stop
$this->mailer->getTransport()->stop();
} catch (\Exception $e) {
// Got Exception while stopping transport.
// We have to set _started to 'false' manually, because due to an exception it is 'true' now.
$t = $this->mailer->getTransport();
$reflection = new \ReflectionClass($t);
$prop = $reflection->getProperty('_started');
$prop->setAccessible(true);
$prop->setValue($t, false);
$prop->setAccessible(false);
}
}
}