Non-Gmail SMTP Login Credentials

I am trying to send an email in Python via Gmail. Here is my code:

import smtplib fromaddr = '......................' toaddrs = '......................' msg = 'Spam email Test' username = '.......' password = '.......' server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login(username, password) server.sendmail(fromaddr, toaddrs, msg) server.quit() 

I get an error message:

 Traceback (most recent call last): File "email_send.py", line 18, in <module> server.login(username, password) File "C:\.....\Python\lib\smtplib.py", line 633 , in login raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepte d. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=1425 7\n5.7.8 {BADCREDENTIALS} s10sm9426107qam.7 - gsmtp') 

This seems to be a login issue. I am sure that my login details are correct, except for one. Should the username be " blah@gmail.com " or just "blah"? I tried the same error.

Any idea what is wrong?

NOTE: all periods are used instead of password paths, email / files, etc.

+24
source share
5 answers

I ran into a similar problem and came across this question. I received an SMTP authentication error, but my username / password was correct. Here is what it fixed. I read this:

https://support.google.com/accounts/answer/6010255

In short, Google does not allow you to log in via smtplib because it has marked this type of login as "less secure", so you need to follow this link when you log in to your Google account and allow access:

https://www.google.com/settings/security/lesssecureapps

Once this is installed (see my screenshot below), it should work.

Less secure apps

Login now works:

 smtpserver = smtplib.SMTP("smtp.gmail.com", 587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo() smtpserver.login(' me@gmail.com ', 'me_pass') 

Answer after change:

 (235, '2.7.0 Accepted') 

Previous answer:

 smtplib.SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 g66sm2224117qgf.37 - gsmtp') 

Still not working? If you still get SMTPAuthenticationError, but now the code is 534, this is because the location is unknown. Follow this link:

https://accounts.google.com/DisplayUnlockCaptcha

Click Continue and this should give you 10 minutes to register your new application. So go on to the next login attempt, and it should work.

It doesn't seem to work right away, you can get stuck with this error in smptlib for a smptlib :

 235 == 'Authentication successful' 503 == 'Error: already authenticated' 

The message says that you must use a browser to log in:

 SMTPAuthenticationError: (534, '5.7.9 Please log in with your web browser and then try again. Learn more at\n5.7.9 https://support.google.com/mail/bin/answer.py?answer=78754 qo11sm4014232igb.17 - gsmtp') 

After enabling "lesssecureapps", try the coffee, go back and try the "DisplayUnlockCaptcha" link again. From user experience, it may take up to an hour for the change to take effect. Then try logging in again.

UPDATE :: See my answer here: How do I send an email from Gmail as a provider using Python?

+60
source

I had the same problem. An authentication error may be related to your security settings, for example, a two-step verification. This will prevent third-party applications from canceling authentication.

Log in to your Google account and use the following links:

Step 1 [Link to disable two-step verification]:

https://myaccount.google.com/security?utm_source=OGB&utm_medium=act#signin

Step 2: [Link to enable less secure applications]

https://myaccount.google.com/u/1/lesssecureapps?pli=1&pageId=none

Everything should be fine now.

+9
source

If you enable 2-step verification, you need to create a special application password instead of a regular password. https://myaccount.google.com/security#signin

+2
source

I had the same problem. And I fix it by creating an application password for an email application on a Mac. You can find it in my account → Security → Google Login → Application Passwords. Below is the link for this. https://myaccount.google.com/apppasswords?utm_source=google-account&utm_medium=web

+2
source

if you get an error (535, b'5.7.8 Username and password are not accepted. More details at \ n5.7.8 https://support.google.com/mail/?p=BadCredentials o60sm2132303pje.21 - gsmtp ')

then just go to your Google account settings in the security section, create a less secure account and enable the less secure button

+2
source

Source: https://habr.com/ru/post/944831/


All Articles