SMTP mailer sends EHLO before 220 ready response received from server #2042

amalg opened this Issue Nov 29, 2012 · 1 comment


None yet

3 participants


I'm having an issue sending SMTP mail to our internal mail server (no auth, no encryption, nothing fancy), as well as to gmail. This is the $config array I'm using;

$config = array(
"protocol" => "smtp",
"smtp_host" => "",
"smtp_port" => "587",
"smtp_timeout" => "5",
"smtp_auth" => FALSE,
"smtp_user" => "",
"smtp_pass" => "",
"set_crlf" => "\r\n",
"set_newline" => "\r\n",
"charset" => "utf-8",
"wordwrap" => TRUE,
"mailtype" => "html"

and this is the first part of the log I'm seeing;

220 xxx.xxxx.xxxx Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Thu, 29 Nov 2012 11:55:01 -0800
The following SMTP error was encountered:
The following SMTP error was encountered:
The following SMTP error was encountered:

So we can see the server connection happening, but then even the hello command is failing, so I opened up a TCP sniffer and found the problem;

You can clearly see that the SMTP client side is connecting, then sending the EHLO immediately, well before the server has sent the 220 ready response following TCP connection. So we hit a race condition where the server is waiting for EHLO and the client is waiting for the server's 250 response, so the TCP connection simply times out and drops.

What needs to happen is the CI mailer needs to WAIT for the server's 220 ready response BEFORE sending EHLO.


The way fsock sockets behave using fgets is blocking read - the script blocks until it gets a response or timeout occurrs. And I'm guessing your read timed out hence the premature HELO write. PR #2256 fixes this by attaching the timeout property to the read/writes as well. So you can simply increase the timeout of read/writes.

@narfbg narfbg closed this Jan 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment