title: Use Python to get an smtp server certificate
body: <p>What's the easiest way to connect to a SMTP server that supports STARTTLS and get its server SSL certificate? I know it can be done using openssl with something like this</p>
  
  <pre><code>openssl s_client -starttls smtp -crlf -connect 192.168.0.1:25
  </code></pre>
  
  <p>How can I do it from within Python and I don't want to call openssl and parse its output. I looked at M2Crypto which is an openssl wrapper, but as far as I can tell that doesn't support starttls. An example of how to do it with a Python library would be very much appreciated.</p>