SMTPAuthenticationError (Python) Email / SMTP Origin: Network Last updated 4 Nov 2026

Python: smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted')

smtp.login() was rejected by the server — wrong credentials, wrong password type, or authentication not allowed for that account.

Exact message you may see smtplib.SMTPAuthenticationError: (535SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted')smtplib.SMTPAuthenticationError (534SMTPAuthenticationError: (530, b'5.7.0 Authentication Required')
Seen on: SMTP Python

Meaning

Check the code in the tuple: 535 means bad credentials, 534 an app password is needed, 530 means authenticate over TLS first. Make sure you call starttls() then ehlo() before login(), and store secrets in environment variables instead of source.

Common causes

  • Wrong username/password or full address missing
  • App password needed (2-Step Verification)
  • login() called before starttls()
  • Account blocked or SMTP disabled
  • Password with non-ASCII characters mishandled

⚡ Quick fix

  1. Use the full email as user and an app password
  2. Call ehlo(), starttls(), ehlo(), then login()
  3. Read the exact code: 535, 534, 530 each mean something different

Detailed fix by platform

Python

  1. import os; s.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])

How to diagnose

  1. Code — 535, 534 or 530?
  2. Order — starttls before login?
  3. Credentials — App password?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Network. Errors that are often confused with or caused by this one (click to open):

530 5.7.0 Authentication Required — SMTP: 530 5.7.0 Must issue a STARTTLS command first / 530 5.7.1 Authentication required (Email / SMTP)530 5.7.0 Authenticat…534 5.7.9 Application-specific password required — SMTP: 534-5.7.9 Application-specific password required. Learn more at https://support.google.com/accounts/answer/185833 (Email / SMTP)534 5.7.9 Application…535 5.7.8 Username and Password not accepted — SMTP: 535-5.7.8 Username and Password not accepted. Learn more at https://support.google.com/mail/?p=BadCredentials (Email / SMTP)535 5.7.8 Username an…ConnectionRefusedError [Errno 111] (SMTP) — Python: ConnectionRefusedError: [Errno 111] Connection refused — smtplib connect to localhost:25 (Email / SMTP)ConnectionRefusedErro…Nodemailer: EAUTH Invalid login — Nodemailer: Error: Invalid login: 535-5.7.8 Username and Password not accepted (code: 'EAUTH', responseCode: 535) (Email / SMTP)Nodemailer: EAUTH Inv…Postfix: SASL authentication failed — Postfix: warning: SASL authentication failure: cannot connect to saslauthd server: No such file or directory (Email / SMTP)Postfix: SASL authent…SmtpClientAuthentication is disabled for the Tenant — SMTP: 535 5.7.139 Authentication unsuccessful, basic authentication is disabled / SmtpClientAuthentication is disabled for the Tenant (Email / SMTP)SmtpClientAuthenticat…SMTPServerDisconnected: Connection unexpectedly closed — Python: smtplib.SMTPServerDisconnected: Connection unexpectedly closed (Email / SMTP)SMTPServerDisconnecte…SMTPAuthe…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.