SMTP error 535 means the server refused your authentication attempt: "authentication credentials invalid". The server understood the AUTH command but did not accept the username and password, token or mechanism you presented. The most common causes are a wrong or outdated password, using a normal account password where the provider requires an app password or API key, a username in the wrong format, authentication attempted before TLS is established, or an account or tenant setting that disables password logins entirely.
Because the server deliberately gives little detail, the fix is a systematic check from the outside in: confirm the host, port and encryption, then the exact username, then the secret type, then provider-side policy. This guide gives that checklist, shows how to test a login without your application in the way and explains the codes you will see from large providers.
What 535 means in the protocol
SMTP authentication is defined by the AUTH extension in RFC 4954, which specifies reply 535 for failed authentication and the enhanced code 5.7.8 for invalid credentials. RFC 4954 also defines 530 for "authentication required" and 534 for a mechanism that is too weak. 535 is permanent for that attempt, but retrying with different credentials is fine. The session usually stays open for a few more attempts, then the server drops it. See 530 authentication required for the neighbouring error and the short 535 reference.
AUTH LOGIN
334 VXNlcm5hbWU6
dXNlckBleGFtcGxlLmNvbQ==
334 UGFzc3dvcmQ6
cGFzc3dvcmQ=
535 5.7.8 Error: authentication failed: Invalid credentialsMessages you will see from common providers
| Provider reply | Likely meaning | Fix |
|---|---|---|
| 535 5.7.8 Username and Password not accepted (Gmail) | Wrong password, or an app password is required | Use a Google app password with 2-step verification, or OAuth. See Gmail SMTP settings |
| 535 5.7.3 Authentication unsuccessful (Microsoft) | Wrong credentials, or the mechanism or account is not allowed | Check the password and account state. See Outlook SMTP settings |
| 535 5.7.139 authentication unsuccessful, SmtpClientAuthentication is disabled (Microsoft 365) | SMTP AUTH client submission is turned off for the tenant or mailbox, or security defaults block it | Administrator enables it for the mailbox or the app moves to OAuth. Confirm in current Microsoft documentation |
| 535 Authentication failed with a Yahoo or iCloud host | Normal password used where an app specific password is required | Create an app password. See Yahoo SMTP settings and iCloud SMTP settings |
| 535 authentication failed from a sending service | Wrong API key or SMTP username, key revoked, wrong region or host | Regenerate and copy the credential again |
| 535 5.7.0 or generic text from a self hosted server | Wrong password, wrong auth backend, or SASL misconfiguration | Check the server's authentication logs |
The exact numbers differ by provider and change over time, so use the text of the reply as the main clue.
Checklist: from the connection inward
- Host, port and encryption. Port 587 with STARTTLS or 465 with implicit TLS are the usual submission choices. Authentication on a plain unencrypted session is often refused. See SMTP settings, ports and TLS and which port to use.
- Username format. Some servers want the full address ([email protected]), some want only the local part, and some want an account ID or an API username that is not an email address at all. Copy the format from your provider's documentation.
- Secret type. Check whether the provider expects the mailbox password, an app password, an API key used as the password, or an OAuth token. See SMTP OAuth 2.0.
- Hidden characters. Copy and paste often adds a trailing space or newline, and secrets with special characters get mangled by shells and configuration files. Quote or escape them correctly.
- Mechanism. The server advertises mechanisms in the EHLO response (AUTH PLAIN LOGIN, for example). Your client must use one of them. See SMTP auth mechanisms.
- Account state. Passwords may have expired or been rotated, the account may be locked after repeated failures, or multi-factor authentication may now be required.
- Provider policy. Basic password authentication is being restricted by several large providers. Check whether your account or tenant still allows it.
Test the login outside your application
Testing with a standalone tool separates a credential problem from an application bug. Swaks, covered in testing SMTP connections, handles TLS and authentication in one command.
swaks --to [email protected] --from [email protected] \
--server smtp.example.com --port 587 --tls \
--auth LOGIN --auth-user 'smtp-user' --auth-password 'secret-value'To see the raw exchange and verify exactly what you are sending, open the session by hand. Base64-encode the username and password without a trailing newline.
printf '%s' 'smtp-user' | base64
printf '%s' 'secret-value' | base64
openssl s_client -connect smtp.example.com:587 -starttls smtp -crlf
EHLO test.example.com
AUTH LOGIN
(paste the base64 username, then the base64 password)A frequent mistake is encoding with a command that appends a newline, such as echo user | base64, which produces a different string from the one the server expects. Use printf '%s' or echo -n. For AUTH PLAIN the string is the authorisation identity, username and password separated by NUL bytes and then encoded, for example printf '\0user\0pass' | base64.
Typical application level mistakes
- Environment variables not loaded. The application reads an empty or stale password because the deployment did not set the variable.
- Different credentials per environment. A development key used in production, or the reverse.
- Wrong TLS mode flags. Setting implicit TLS on port 587 or STARTTLS on port 465 usually fails before authentication, but some clients report it as a login error.
- Library defaults. Some libraries try to authenticate before upgrading to TLS or pick a mechanism the server does not offer. See Python smtplib, Nodemailer and PHPMailer for correct settings.
- Special characters. A password containing
#,$or quotes broken by a .env parser or shell.
Security aspects of repeated 535 errors
Failed authentication is also what a credential stuffing attack looks like. Servers respond with delays, lockouts and IP bans after repeated failures, so a misconfigured application that retries every second can lock out the real account or get your server address blocked. Back off after a 535, alert a human, and do not loop. If you operate the server, watch for bursts of 535 from unknown addresses. See SMTP brute force protection and API key security and rotation. After a leak, rotate the credential at once. See rotating an API key.
Keep credentials working over time
Most 535 incidents in production are not first-time setup errors; they are drift. A password is rotated in the provider console but not in the application, a staff member leaves and their mailbox is disabled while a script still uses it, or MFA is enforced for an account that a service was logging in to. Treat the SMTP credential as a managed asset with an owner and a rotation date.
Give each application its own credential so that revoking one does not break the others, record where each credential is used, and test the login from a scheduled health check that sends to a monitored mailbox. A failing health check at 03:00 is much cheaper than discovering the problem when a customer asks why their password reset never arrived. Where a provider offers IP restrictions on credentials, document the allowed addresses and update them when servers change.
Troubleshooting table
| Symptom | Likely cause | Action |
|---|---|---|
| 535 immediately after AUTH on port 25 | Authentication not allowed on that port or without TLS | Use 587 with STARTTLS or 465 |
| Works with swaks, fails in the application | Application encoding, env variable or TLS settings | Print the effective settings, check hidden characters |
| Worked yesterday, fails today | Password rotated, key revoked or policy change | Generate a new credential and read provider announcements |
| 535 only from some servers | IP restrictions on the account or key | Allow the server's IP address in the provider panel |
| 535 for Gmail or Yahoo with correct password | App password required | Create one; the normal password is not accepted |
| 535 after enabling MFA | Account now needs an app password or token | Switch to the new secret type |
Next steps
Move from user passwords to scoped, revocable credentials: an API key or app password per application, stored in a secret manager, never in source control. Where the provider supports OAuth, prefer it. Log authentication failures with the username and source IP, but never log the secret itself. A short runbook that lists host, port, username format and secret type for each integration will save hours the next time a 535 appears.
Scoped credentials for every application Create separate SMTP credentials or API keys per system and revoke them without touching the others.
References and further reading
Frequently asked questions
What does SMTP error 535 authentication failed mean?
The server received your login but rejected the username, password, token or mechanism you presented.
Why does Gmail say Username and Password not accepted?
Usually because an app password or OAuth is required instead of your normal account password, or the credentials are wrong.
How do I test SMTP authentication?
Use swaks or openssl s_client with the same host, port, username and password as your application, outside the application itself.
Can a correct password still return 535?
Yes. The account may not allow basic password authentication, the username format may be wrong, or the password may be mangled by encoding.
Should my application retry after a 535?
No tight retry loop. Repeated failures can lock the account, so stop, alert and fix the credentials.