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.
smtplib.SMTPAuthenticationError: (535SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted')smtplib.SMTPAuthenticationError (534SMTPAuthenticationError: (530, b'5.7.0 Authentication Required') 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 beforestarttls()- Account blocked or SMTP disabled
- Password with non-ASCII characters mishandled
⚡ Quick fix
- Use the full email as user and an app password
- Call
ehlo(),starttls(),ehlo(), thenlogin() - Read the exact code: 535, 534, 530 each mean something different
Detailed fix by platform
Python
import os; s.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])
How to diagnose
- Code — 535, 534 or 530?
- Order — starttls before login?
- 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:
Similar errors
- 530 5.7.0 Authentication Required SMTP: 530 5.7.0 Must issue a STARTTLS command first / 530 5.7.1 Authentication required
- 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
- 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
Most viewed in Email / SMTP
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026