title: send SMTP email for office365 with python using tls/ssl
body: <p>i'm trying to create a python script that sends emails with some messages.
  my setup is based on a smtp.office365.com. i created some script to do the job.</p>
  
  <pre><code>#!/usr/bin/python
  
  print ("HI! let's start")  
  import smtplib  
  import getpass
  
  port=587                                                                                                                    
  smtp_server="smtp.office365.com"  
  sender_email='mymail@something.com'  
  receiver_email='mymail@something.com'  
  print ("defining server")  
  server = smtplib.SMTP(smtp_server,port)
  
  password=getpass.getpass("enter password")
  
  message='''
  Hi,
  THIS IS A TEST MESSAGE.
  '''
  
  print ("logging in")  
  server.login(sender_email,password)  
  print ("sending mail now")  
  server_sendmail(sender_email,receiver_email,message)  
  print ("all must be done by now")
  </code></pre>
  
  <p>But due to some reasons, it gets stuck after printing "defining server". and never reaches to asking for password. apparently the smtplib.SMTP command hangs. can you tell why this happens and how to get rid of it? my setup is as following :</p>
  
  <pre><code>Server: smtp.office365.com
  /sjmail.com
  security : STARTTLS
  Port : 587
  </code></pre>