Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swiftmailer completely broken for smtp?

Tags:

php

Just updated my swiftmailer checkout to the latest version 4.3.0. The following VERY simple code no longer works, and the connection times out:

<? 
require_once 'Swift-4.3.0/lib/swift_required.php';

$transport = Swift_SmtpTransport::newInstance('email-smtp.us-east-1.amazonaws.com',465, 'tls')
  ->setUsername('USERNAME')
  ->setPassword('PASSWORD')
  ;
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Yo')
  ->setFrom(array('[email protected]' => 'Josh'))
  ->setTo(array('[email protected]'))
  ->setBody('Here is the message itself')
  ;

$result = $mailer->send($message);

I then get the following:

PHP Fatal error:  Uncaught exception 'Swift_IoException' with message 'Connection to tcp://email-smtp.us-east-1.amazonaws.com:465 Timed Out' in /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/StreamBuffer.php:169
Stack trace:
#0 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(400): Swift_Transport_StreamBuffer->readLine(0)
#1 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(291): Swift_Transport_AbstractSmtpTransport->_getFullResponse(0)
#2 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/AbstractSmtpTransport.php(119): Swift_Transport_AbstractSmtpTransport->_readGreeting()
#3 /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
#4 /home/jnankin/Desktop/email.php(17): Swift_Mailer->send(Object(Swift_Message))
#5 {main}
  thrown in /home/jnankin/Desktop/Swift-4.3.0/lib/classes/Swift/Transport/StreamBuffer.php on line 169

UPDATE: This exact same code (without any changes whatsoever) works in version 4.1.2. Version 4.1.3 this no longer works. I've tried different SMTP servers: mailgun, sendgrid, etc... this seems swiftmailer specific.

like image 576
Josh Nankin Avatar asked Dec 06 '22 09:12

Josh Nankin


1 Answers

Looks like starting in version 4.1.3 swiftmailer added starttls support. In version 4.1.2 and eariler, using port 465 and specifying 'tls' as the encryption method worked fine. However 4.1.3 looks like it does not support using a tls wrapper and only allows starttls. In other words "tls" stopped meaning "tls wrapper" and started meaning "starttls". Thus, changing the port to 587 instead of 465 (as the SES documentation says should be used for starttls connections) solved the problem for me.

Very bad move by swiftmailer imho.

like image 92
Josh Nankin Avatar answered Dec 25 '22 11:12

Josh Nankin