0

I'm attempting to use smtplib to set up a python script that will email out alert notifications. I don't need anything fancy, so I figured I'd stick with the basics and use SMTP for my messages. Following one of the many available online examples, my attempt to do so begins

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login('username','password')

but at this point fails with an SMTPAuthenticationError 534, telling me to log on via my web browser. When I so, gmail has emailed me saying the sign in failed because it came from "an app that doesn't meet modern security standards."

I've seen some people having similar problems solved by changing their gmail account to accept logon from less secure apps, but did this myself and continued to get the same error message.

So is plain old SMTP not going to cut it and I need to get fancy? What am I doing wrong, or what can I do instead to make this work?

Empiromancer
  • 3,778
  • 1
  • 22
  • 53
  • 1
    [This question](http://stackoverflow.com/q/25413301/113848) is about IMAP, but I suspect the same solutions apply. One of the suggestions is to authenticate using OAuth; [this question](http://stackoverflow.com/q/11445523/113848) addresses how to do that with smtplib. – legoscia Jan 22 '16 at 18:07
  • 1
    enable two factor authentication, and generate an app password for this application. That worked for me about 3 years ago – inspectorG4dget Jan 22 '16 at 18:07

1 Answers1

-1

As it turns out, my attempts to set gmail to accept logon from less secure apps had (for whatever reason) not taken the first time I tried. Going to https://myaccount.google.com/security?pli=1 and turning this setting on allowed me to access successfully.

The comments pointing me towards oauth2 and app passwords are most helpful though, and I now that I've accomplished the bare bones I may look into those for more robust long-term approaches. Thank you!

Empiromancer
  • 3,778
  • 1
  • 22
  • 53