The error 534 5.7.9 Application-specific password required means Gmail rejected your SMTP login because you tried to authenticate with the normal account password on an account that no longer accepts it for this kind of connection. The server is telling you that this account is protected by 2-Step Verification (or by an administrator policy) and the application must present either an app password or an OAuth 2.0 token instead.
The fix is almost always one of two things: create an app password and use it in place of the account password, or switch the application to OAuth 2.0. Which of the two is available to you depends on whether the account is a personal Gmail account or a Google Workspace account managed by an administrator. This guide walks through the diagnosis, both fixes and the mistakes that cause the error to come back.
What the error actually means
SMTP replies of the form 5.7.x are security and policy rejections. Code 534 is a permanent failure for the authentication command: the mechanism you used is not strong enough for this account. A typical transcript looks like this, and you can reproduce it with any SMTP client that logs the conversation.
S: 220 smtp.gmail.com ESMTP ready
C: EHLO client.example.com
S: 250-smtp.gmail.com at your service
S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
S: 250 STARTTLS
C: AUTH PLAIN AGFsaWNlQGdtYWlsLmNvbQBwYXNzd29yZA==
S: 534-5.7.9 Application-specific password required.
S: 534 5.7.9 For more information, see the Google Account help pagesThe exact wording and the list of advertised mechanisms change over time, so treat the transcript as an illustration. The important part is the reply code and the enhanced status code. For a broader catalogue of these codes see the SMTP and enhanced status code list.
Why it happens
- 2-Step Verification is on. Once a second factor is enabled, applications that can only send a username and password cannot complete the login with the account password.
- Legacy password sign-in is no longer allowed. Google has been withdrawing the old option that let less secure applications sign in with the account password. Availability differs between personal and Workspace accounts and has changed over the years, so check Google's current account help.
- Administrator policy. On Workspace, an admin can require stronger sign-in methods, which makes a plain password fail even when the user has not turned on anything personally.
- An old app password was revoked. Changing the Google account password or removing the app password invalidates it, and the next login falls back to this error or to 535.
- The wrong credential was pasted. The account password or an expired token is stored in the application configuration.
Fix 1: create and use an app password
An app password is a 16 character code generated by Google that works only for sign-in from an application that cannot show a second factor prompt. It requires 2-Step Verification to be enabled on the account. Menu names move between releases, so follow the current Google Account help page for app passwords if your screen differs from the steps below.
- Sign in to the Google Account that will send the mail and open the Security settings.
- Make sure 2-Step Verification is turned on. App passwords do not appear without it.
- Open the app passwords page, give the password a name such as the application or server it will be used on, and generate it.
- Copy the 16 characters once. Google does not show them again. Spaces in the displayed code are only for readability; enter it without spaces if your client complains.
- Paste it into the SMTP password field of your application, keeping the username as the full Gmail address.
- Save, restart the sending process if it caches credentials and send a test message.
Treat the app password like any secret: store it in a secrets manager or environment variable, never in a repository, and create one per application so that you can revoke it without breaking everything else. If you do not see the option at all, the account may be managed by an administrator who has disabled it, or it may be enrolled in a program that restricts it. See when you need an app password for the general picture.
Fix 2: use OAuth 2.0 instead
For a business application, OAuth 2.0 is the better answer. You register an application in Google Cloud, request the Gmail scope, obtain a refresh token with the user's consent and exchange it for short lived access tokens. The SMTP login then uses the XOAUTH2 mechanism with the access token in place of a password. The advantages are that no long lived password is stored, access can be revoked per application and administrators can audit it. The disadvantage is more setup, and the consent screen and verification requirements are governed by Google's current rules. Read OAuth 2.0 for SMTP and IMAP and SMTP authentication mechanisms before choosing.
Correct connection settings for smtp.gmail.com
| Setting | Value |
|---|---|
| Host | smtp.gmail.com |
| Port 587 | STARTTLS, upgrade the connection before authenticating |
| Port 465 | Implicit TLS (SMTPS), TLS from the first byte |
| Username | Full email address |
| Password | App password (16 characters), or an OAuth 2.0 access token with XOAUTH2 |
| From address | Must be the authenticated account or a verified Send mail as alias |
A minimal test with Python shows the same login the failing application performs. Replace the placeholders and keep the real value in an environment variable.
import os, smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = 'SMTP test'
msg.set_content('Hello from an app password test.')
with smtplib.SMTP('smtp.gmail.com', 587, timeout=30) as s:
s.set_debuglevel(1)
s.starttls()
s.login('[email protected]', os.environ['GMAIL_APP_PASSWORD'])
s.send_message(msg)If this script succeeds and your application still fails, the application is not using the value you think it is. See Gmail SMTP settings and limits and the language guides such as Python smtplib.
Google Workspace specifics
On Workspace the answer is partly out of the user's hands. An administrator controls whether 2-Step Verification is enforced, whether app passwords may be created, and which third party applications may use OAuth. If the app password option is missing, ask the administrator, rather than trying to bypass the policy. For servers that only need to relay mail from known systems, Workspace offers an SMTP relay service configured by the administrator that authenticates by IP address or by credentials; read the Workspace SMTP relay guide and confirm the details in Google's current documentation.
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| 534 5.7.9 persists after entering an app password | The application still sends the account password or an old cached value | Re-enter the secret, restart the service and inspect the debug log of the SMTP conversation |
| 535 5.7.8 Username and Password not accepted | App password typed wrongly, revoked, or username is not the full address | Generate a new app password and retest. See error 535 |
| No app passwords option in the account | 2-Step Verification off, admin policy, or account type restriction | Enable 2-Step Verification or ask the Workspace administrator |
| 530 5.7.0 Must issue a STARTTLS command first | Login attempted before TLS on port 587 | Enable STARTTLS in the client. See error 530 |
| Works for a while, then fails | Google password changed or password revoked | Create a new app password and update the secret store |
| Daily sending limit errors | Account limit reached | See Gmail sending limits |
When Gmail is the wrong tool
A personal or Workspace mailbox is designed for people, with daily recipient limits and no per message delivery events. For transactional mail, newsletters or anything with more than a modest volume, a dedicated sending service with API keys, per message logs and webhooks is easier to operate than app passwords and refresh tokens. See when to move off Gmail.
Next steps
- Create a separate app password for each application and label it clearly.
- Prefer OAuth 2.0 where your library supports XOAUTH2.
- Keep secrets out of source control and rotate them when staff leave.
- Log the SMTP conversation during setup so you can see the exact reply code.
- If you send significant volume, plan a move to a service built for it.
Need a sending service without app passwords? Authenticate with SMTP credentials or an API key and see every delivery event.
References and further reading
Frequently asked questions
What does Gmail error 534 5.7.9 mean?
Gmail refused the login because the account needs an application-specific password or OAuth 2.0 instead of the normal account password.
How do I fix application-specific password required?
Enable 2-Step Verification on the account, generate an app password and use it as the SMTP password in your application.
Why can I not find the app passwords option?
2-Step Verification may be off, or a Workspace administrator may have disabled app passwords. Ask the administrator or use OAuth 2.0.
Is OAuth 2.0 better than an app password?
For business applications, generally yes, because no long lived password is stored and access can be revoked per application, but setup is more involved.
Which port should I use with smtp.gmail.com?
Use port 587 with STARTTLS or port 465 with implicit TLS, and authenticate only after the connection is encrypted.