title: Why is SwiftMailer throwing "Internal Server Error"?
body: <p>I am using Symfony + SwiftMailer and getting the following error from SwiftMailer:</p>
  
  <pre><code>500 | Internal Server Error | Swift_TransportException
  Expected response code 220 but got code "", with message ""
  </code></pre>
  
  <p>and can't figure out why. I am using hMailServer on my local machine, and have setup my factories.yml file (as I'm using Symfony) as follows:</p>
  
  <pre><code>  mailer:
      class: sfMailer
      param:
        logging: %SF_LOGGING_ENABLED%
        charset: %SF_CHARSET%
        delivery_strategy: realtime
        transport:
          class: Swift_SmtpTransport
          param:
            host: splodge.loc
            port: 25
            encryption: ~
            username:   ~
            password:   ~
  </code></pre>
  
  <p>I'm using the following code to send:</p>
  
  <pre><code>$message = $this-&gt;getMailer()-&gt;compose(
      'noreply@splodge.loc',
      'info@splodge.loc',
      'Reset Password', 
      'Message'
  );
  $result = $this-&gt;getMailer()-&gt;send($message);
  </code></pre>
  
  <p>Has anyone had an issue like this before?</p>
  
  <p>I have found that sometimes, and very randomly, the send goes through, but every other time, I get the above error message. So constantly refreshing the page that sends the mail, fails unpredictably, and as the code sometimes works, it's kinda hard to figure out what's wrong. </p>
  
  <p>Any help will be highly appreciated!</p>
  
  <hr>
  
  <p>Further investigation has shown that the SMTP server does send [220 localhost ESMTP], but after taking a look at hMailServer logs, I discovered the following:</p>
  
  <pre><code>"TCPIP" 5232    "2010-06-16 11:40:54.043"   "TCPConnection - Posting AcceptEx on 0.0.0.0:25"
  "DEBUG" 5232    "2010-06-16 11:40:54.043"   "Creating session 51"
  "SMTPD" 5232    51  "2010-06-16 11:40:54.043"   "127.0.0.1" "SENT: 220 localhost ESMTP"
  "DEBUG" 5296    "2010-06-16 11:40:54.199"   "The read operation failed. Bytes transferred: 0 Remote IP: 127.0.0.1, Session: 51, Code: 10054, Message: An existing connection was forcibly closed by the remote host"
  "DEBUG" 5296    "2010-06-16 11:40:54.199"   "Ending session 51"
  </code></pre>
  
  <p>Could it be that SwiftMailer is HELO/EHLOing too early, and that this is simply a time issue? Can I delay the HELO transmission a bit?</p>
  
  <p>The good logs, when the thing actually sends looks as follows:</p>
  
  <pre><code>"TCPIP" 5232    "2010-06-16 11:42:21.278"   "TCPConnection - Posting AcceptEx on 0.0.0.0:25"
  "DEBUG" 5232    "2010-06-16 11:42:21.294"   "Creating session 54"
  "SMTPD" 5232    54  "2010-06-16 11:42:21.294"   "127.0.0.1" "SENT: 220 localhost ESMTP"
  "SMTPD" 5224    54  "2010-06-16 11:42:21.294"   "127.0.0.1" "RECEIVED: EHLO splodge.loc"
  </code></pre>
  
  <p>So it has to be to do with the HELO/EHLO acknowledgement. Please advise! :)</p>