Python sending email won't work, and is giving long error messages
Question: I'm testing a python script to send e-mail to myself:

    
    
    import smtplib
    fromaddr = '----------@gmail.com'
    toaddrs  = '----------@gmail.com'
    msg = 'GRRRRR!!!!!!'
    username = '----------@gmail.com'
    password = '----------'
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo()
    server.starttls()
    server.login(username, password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    

Where "----------" means "private information." This is the error message I
get:

    
    
    Traceback (most recent call last):
      File "ms.py", line 10, in <module>
        server.login(username, password)
      File "/usr/lib/python2.7/smtplib.py", line 615, in login
        raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvXa\n5.7.14 z7t5LRUd-e-nGxiMetNBY2KaLd8EP3SJVhw2EwccDQjlUi0FxHegAH2YrpvKdYIX2lHz9N\n5.7.14 cMZ_w8kPxuXXhBPMbXA26tWu_HM0tt_4IC8aEct5VRz7z1J22epkLWXUx-COwh4rt2K2-_\n5.7.14 1Lw71Ag70CBpsqYpfzScV-_mF7zHl_NFRflAn5sFnPftR_bX6hhGAHxj5rz1bx0U44sByk\n5.7.14 t-arL3mQhKu-nfFzkcIvjlzuUh3w> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 p18sm2343352qkh.10 - gsmtp')
    

What am I doing wrong?


Answer: You might need:

`server = smtplib.SMTP_SSL('smtp.gmail.com:465')`

instead of:

    
    
    server = smtplib.SMTP('smtp.gmail.com:587')
    

and probably don't need the .ehlo ()

See also <https://support.google.com/accounts/answer/185833>

