import smtplib
smtpObj = smtplib.SMTP('smtp.gmail.com', 587) # Create SMTP object
smtpObj.ehlo() # Sending the hello message, If the first number return is 250, the connection succeeded
smtpObj.starttls() # For port 587, there is a need to start tls connection, for port 445 (ssl) we can skip this step, if the return value is 220 the server is ready.
password = raw_input('Please enter your passowrd: ')
smtpObj.login('test@gmail.com', password) # The user name and password
smtpObj.sendmail('test@gmail.com', 'test@gmail.com', 'Subject: How are you?\nLong time no see') # Sender, receiver and subject, return value 235 means that the connection went well.
# If the 'sendmail' function failed, it will return dictionary of each recipient that the email fail to send the email, empty dictionary = success.
smtpObj.quit() # Close the connection, the 221 return value means tha the connection is ending.
print ('Email sent :)')