Search code examples
pythonamazon-web-servicessmtpgmail

Using Gmail Through Python Authentication Error


*EDIT: SOLVED IT (answer below)

I'm getting an authentication error 534 from gmail when I try to run the following code:

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login("[email protected]", "password")
    msg = "Hello from the other side!"
    server.sendmail("[email protected]", "[email protected]", msg)
    server.quit()
    return 'Message Sent'

I also noticed that google picked up the login attempt and flagged it as a suspicious device because I'm runnning the code from a server on AWS in another state... however, I flagged it as my device, and I'm still getting the same error. What should I do?

*I also DID turn on access for less secure apps to login.


Solution

  • After telling google that it WAS my device, I just had to do this before the changes could propagate!

    https://accounts.google.com/DisplayUnlockCaptcha

    Problem = Solved