title: SMTP_SSL SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
body: <p>This issue is related to smtplib's SMTP_SSL connection.</p>
  
  <p>While connection with SMTP (without ssl) it's working.</p>
  
  <p>While trying the same host &amp; port in SMTP_SSL, error raised. The error is based on host only, The gmail settings also works fine.</p>
  
  <p>Please check the below example and let me know if any changes needed for outlook &amp; office365.</p>
  
  <pre><code>In [1]: import smtplib
  
  In [10]: smtplib.SMTP_SSL('smtp.gmail.com', 465, timeout=100)
  Out[10]: &lt;smtplib.SMTP_SSL instance at 0x109ccaf38&gt;
  
  In [2]: smtplib.SMTP('smtp-mail.outlook.com', 587, timeout=100)
  Out[1]: &lt;smtplib.SMTP instance at 0x10a00bb90&gt;
  
  In [3]: smtplib.SMTP_SSL('smtp-mail.outlook.com', 587, timeout=100)
  ---------------------------------------------------------------------------
  SSLError                                  Traceback (most recent call last)
  &lt;ipython-input-9-f0c5b0de4e24&gt; in &lt;module&gt;()
  ----&gt; 1 smtplib.SMTP_SSL('smtp-mail.outlook.com', 587, timeout=100)
  
  /python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, keyfile, certfile, timeout)
      794             self.keyfile = keyfile
      795             self.certfile = certfile
  --&gt; 796             SMTP.__init__(self, host, port, local_hostname, timeout)
      797 
      798         def _get_socket(self, host, port, timeout):
  
  python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, timeout)
      254         self.esmtp_features = {}
      255         if host:
  --&gt; 256             (code, msg) = self.connect(host, port)
      257             if code != 220:
      258                 raise SMTPConnectError(code, msg)
  
  python2.7/smtplib.pyc in connect(self, host, port)
      314         if self.debuglevel &gt; 0:
      315             print&gt;&gt;stderr, 'connect:', (host, port)
  --&gt; 316         self.sock = self._get_socket(host, port, self.timeout)
      317         (code, msg) = self.getreply()
      318         if self.debuglevel &gt; 0:
  
  python2.7/smtplib.pyc in _get_socket(self, host, port, timeout)
      800                 print&gt;&gt;stderr, 'connect:', (host, port)
      801             new_socket = socket.create_connection((host, port), timeout)
  --&gt; 802             new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
      803             self.file = SSLFakeFile(new_socket)
      804             return new_socket
  
  python2.7/ssl.pyc in wrap_socket(sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, suppress_ragged_eofs, ciphers)
      909                      do_handshake_on_connect=do_handshake_on_connect,
      910                      suppress_ragged_eofs=suppress_ragged_eofs,
  --&gt; 911                      ciphers=ciphers)
      912 
      913 # some utility functions
  
  python2.7/ssl.pyc in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context)
      577                         # non-blocking
      578                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
  --&gt; 579                     self.do_handshake()
      580 
      581             except (OSError, ValueError):
  
  python2.7/ssl.pyc in do_handshake(self, block)
      806             if timeout == 0.0 and block:
      807                 self.settimeout(None)
  --&gt; 808             self._sslobj.do_handshake()
      809         finally:
      810             self.settimeout(timeout)
  
  SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
  </code></pre>
  
  <p>Ref URL: <a href="https://docs.python.org/2/library/smtplib.html#smtplib.SMTP_SSL" rel="nofollow noreferrer">https://docs.python.org/2/library/smtplib.html#smtplib.SMTP_SSL</a></p>