Gmail SMTP login fails with 535 or 534 5.7.14
535-5.7.8 Username and Password not acceptedShort answer
Gmail turned your sign-in down. Usually the app uses the normal account password where Google requires an app password or OAuth, the account has no 2-Step Verification so no app password exists, or Google wants a browser sign-in first. Check which one, then create an app password or move to OAuth.
Fix it fast
1Find out which cause you have
Try the same login by hand with Python. It shows the exact code and text Google returns, outside your app.
python3 - <<'PY' import smtplib, ssl, getpass s = smtplib.SMTP("smtp.gmail.com", 587) s.starttls(context=ssl.create_default_context()) try: s.login(input("user: "), getpass.getpass("password: ")) print("login ok") except smtplib.SMTPAuthenticationError as e: print(e.smtp_code, e.smtp_error) PY2Match what you see, then jump to its fix
- 1
535 Username and Password not accepted, although the password works in the browser.The normal account password is used instead of an app passwordFix - 2
The App Passwords page is missing, or the account is a work or school account.No app password can be created for this accountFix - 3
534-5.7.14 Please log in via your web browser and then try again.Google asks for a browser sign-in first (534 5.7.14)Fix
- 1
What does the error look like?
535-5.7.8 Username and Password not accepted534-5.7.14 Please log in via your web browser and then try again.smtplib.SMTPAuthenticationError: (535, ...)
Cause 1 of 3
The normal account password is used instead of an app password
1Check
Google answers 535 when the username or password is refused, and answers with an application-specific password required message when the account needs an app password. If you typed the real account password into your app, that is the cause.
echo 'Compare the password in your app config with the one at myaccount.google.com/apppasswords'2Fix
Create an app password for the account and put it in the app in place of the normal password. Use the full email address as the username.
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=me@gmail.com
MAIL_PASSWORD=<app password>3Verify
Run the first-step script with the app password; it prints login ok.
python3 -c "print('re-run the first-step script')"Confirmed by knowledge.workspace.google.com
Cause 2 of 3
No app password can be created for this account
1Check
App passwords need 2-Step Verification. The option is also absent when 2-Step Verification uses only security keys, when the account is a work, school or other organization account, or when Advanced Protection is on.
echo 'Open https://myaccount.google.com/security and look at 2-Step Verification'2Fix
Turn on 2-Step Verification for a personal account, then create the app password. For Workspace accounts, Google no longer supports password sign-in by third-party apps (since 1 May 2025): use OAuth, or the SMTP relay service at smtp-relay.gmail.com.
host: smtp-relay.gmail.com
port: 587
# relay authenticates your server by IP address in the Admin console3Verify
The App Passwords page now lists the app, or the relay accepts mail from your server IP.
openssl s_client -starttls smtp -connect smtp-relay.gmail.com:587 -brief </dev/nullConfirmed by support.google.com
Cause 3 of 3
Google asks for a browser sign-in first (534 5.7.14)
1Check
This code means the sign-in has to be completed through a web browser before the SMTP client may try again.
echo 'Sign in to the sending account in a browser from the same network and read any security prompt'2Fix
Sign in to the account in a browser, clear the prompt, then retry the client. If it keeps coming back, stop sending the plain password and switch to an app password or OAuth, which Google lists as the supported ways.
# retry after the browser sign-in, with an app password
python3 first_step.py3Verify
The first-step script no longer prints 534.
python3 first_step.pyConfirmed by knowledge.workspace.google.com
How do I stop it coming back?
- Store the app password in an environment variable, and rotate it if it leaks.
- Use the full email address as the username, as Google's SMTP settings page asks for.
- Prefer OAuth for anything long-lived; Google says app passwords are not recommended and unnecessary in most cases.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Gmail rejects your mail with 530 5.5.1 Authentication Required
530 5.5.1 Authentication Required
Gmail refuses to accept a message from a connection that has not signed in.
3 causes, each with a fixDjango send_mail fails or hangs with an SSL error
smtplib.SMTPException raised from send_mail()
Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).
4 causes, each with a fixGmail SMTP blocks you with 454 4.7.0 Too many login attempts
SMTP Error: 454 4.7.0 Too many login attempts
454 4.7.0 is a temporary block.
2 causes, each with a fixPython IMAP OAuth login to a shared mailbox in Microsoft 365 fails
imaplib.IMAP4.error: AUTHENTICATE failed.
Exchange Online accepts an OAuth token for IMAP only if the SASL user name is right and the token's identity has access to that mailbox.
4 causes, each with a fixPython says module smtplib has no attribute SMTP
print(smtplib.__file__) shows a path inside your own project
Python found a different smtplib than the standard one.
2 causes, each with a fixPython smtplib raises SMTPServerDisconnected: please run connect() first
smtplib.SMTPServerDisconnected: please run connect() first
smtplib raises SMTPServerDisconnected when you use an SMTP object that is not connected.
3 causes, each with a fix