title: openssl to negotiate SSL encryption for STARTTLS
body: <p>I'm using openssl to connect to an SMTP server normally (without encryption), send a STARTTLS command, negotiate the SSL encryption, and then interact with the encrypted session. </p>
  
  <p>This is the command I'm using (through telnet):</p>
  
  <pre><code>openssl s_client -starttls smtp -crlf -connect 1.2.3.4:25
  </code></pre>
  
  <p>How can I ensure that TLS handshake was successful?</p>
  
  <p>This is the sequence of commands used so far:</p>
  
  <pre><code>&lt;&lt; 220 example.com ESMTP ready
  &gt;&gt; EHLO localhost
  &lt;&lt; 250-smtp.mail.yahoo.com
  &lt;&lt; 250-PIPELINING
  &lt;&lt; 250-AUTH PLAIN LOGIN CRAM-MD5
  &lt;&lt; 250 STARTTLS
  &gt;&gt; STARTTLS
  &lt;&lt; 220 2.0.0 Start TLS
  &gt;&gt; openssl s_client -starttls smtp -crlf -connect 127.0.0.1:587    
  </code></pre>