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

**Code:** `SMTPAuthenticationError (Python)` · **Category:** Email / SMTP · **Seen on:** SMTP, Python

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/email/python-smtpauthenticationerror)
