Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Gmail SMTP login fails with 535 or 534 5.7.14

Error535-5.7.8 Username and Password not accepted

Short 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.

  • Applies to Python 3.12, smtp.gmail.com
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)
    PY
  2. 2Match what you see, then jump to its fix

    1. 1535 Username and Password not accepted, although the password works in the browser.The normal account password is used instead of an app passwordFix
    2. 2The App Passwords page is missing, or the account is a work or school account.No app password can be created for this accountFix
    3. 3534-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

What does the error look like?

  • 535-5.7.8 Username and Password not accepted
  • 534-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

Did this fix it?

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 console

3Verify

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/null

Confirmed by support.google.com

Did this fix it?

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.py

3Verify

The first-step script no longer prints 534.

python3 first_step.py

Confirmed by knowledge.workspace.google.com

Did this fix it?

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:

Related fixes

Email

Django 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.