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
There is a rude option: stop the transport explicitly. On subsequent calls of the method sendMail, SwiftMailer will check whether the transport is up (it is not, now) and start it again. IMNSHO, SwiftMailer should intercept the SMTP timeout and reconnect automatically.But, for now, this is the workaround:
function sendMail($your_args) {
try{
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john@doe.com' => 'John Doe'))
->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
->setBody('Here is the message itself');
$result = $mailer->send($message);
$mailer->getTransport()->stop();
} catch (Swift_TransportException $e) {
//this should be caught to understand if the issue is on transport
} catch (Exception $e) {
//something else happened
}
}