Gmail rejects your mail with 530 5.5.1 Authentication Required
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication RequiredShort answer
Gmail refuses to accept a message from a connection that has not signed in. In practice the app never sent credentials, sent them before the connection was encrypted, or used an ordinary account password that Google no longer accepts. Check the order of connect, TLS and sign-in, then use an app password or OAuth.
Fix it fast
1Find out which cause you have
Run the smallest possible send with the standard library of your language and watch which step fails: connect, STARTTLS or login. Python prints the SMTP conversation when debug is on.
python3 - <<'PY' import smtplib, ssl s = smtplib.SMTP("smtp.gmail.com", 587) s.set_debuglevel(1) s.ehlo() s.starttls(context=ssl.create_default_context()) s.ehlo() print(s.esmtp_features.get("auth")) PY2Match what you see, then jump to its fix
- 1
The server answers 530 right after MAIL FROM, and your code has no credentials or no login call.The app never signs inFix - 2
In Go the send fails before any credentials leave your machine. In C# the call works only after EnableSsl is set.Sign-in happens on a connection that is not encryptedFix - 3
Authentication is attempted, yet Gmail still answers with an authentication error. Workspace accounts have no password sign-in for apps since 1 May 2025.An ordinary account password is used where Google wants an app password or OAuthFix
- 1
What does the error look like?
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required530 5.5.1 Authentication Required
Cause 1 of 3
The app never signs in
1Check
Search the sending code for the place where the username and password are given to the SMTP client. An SMTP server that requires authentication refuses the message when none was made.
grep -rn -E "Credentials|NetworkCredential|PlainAuth|\.login\(" src/2Fix
Give the client the account and an app password before sending. In C# set Credentials on the SmtpClient. In Go pass an smtp.Auth value to smtp.SendMail. In Python call login() before sendmail().
// C#
client.Credentials = new System.Net.NetworkCredential("me@gmail.com", appPassword);
// Go
auth := smtp.PlainAuth("", "me@gmail.com", appPassword, "smtp.gmail.com")
err := smtp.SendMail("smtp.gmail.com:587", auth, from, to, msg)
# Python
server.login("me@gmail.com", app_password)3Verify
The message is accepted and no 530 appears in the output.
python3 -c "import smtplib; print(smtplib.SMTP.login.__doc__[:60])"Confirmed by docs.python.org
Cause 2 of 3
Sign-in happens on a connection that is not encrypted
1Check
Go's PlainAuth sends credentials only over TLS or to localhost, and otherwise fails without sending them. .NET's SmtpClient has EnableSsl set to false by default.
grep -rn -E "EnableSsl|StartTLS|starttls|SMTP_SSL" src/2Fix
Connect to smtp.gmail.com on port 587 and upgrade with STARTTLS before signing in (EnableSsl = true in C#, starttls() in Python, SendMail does it for you in Go). Port 465 expects TLS from the first byte, which .NET SmtpClient does not support.
// C#
var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587) { EnableSsl = true };3Verify
The send succeeds on port 587 with TLS on.
openssl s_client -starttls smtp -connect smtp.gmail.com:587 -brief </dev/nullConfirmed by learn.microsoft.com
Cause 3 of 3
An ordinary account password is used where Google wants an app password or OAuth
1Check
Is the account a Google Workspace account, and is 2-Step Verification on? App passwords work only with 2-Step Verification, and are not offered to accounts that use only security keys, to work or school accounts that block them, or to Advanced Protection accounts.
echo 'Open https://myaccount.google.com/apppasswords while signed in as the sending account'2Fix
Create an app password at myaccount.google.com/apppasswords and use it in place of the account password. For Workspace accounts and for new builds, use OAuth, or send through the SMTP relay service at smtp-relay.gmail.com, which authenticates by IP address.
host: smtp.gmail.com
port: 587
username: me@gmail.com
password: <16-digit app password>3Verify
Run the first-step script again, add a login() call with the app password, and confirm it returns without an exception.
python3 -c "import smtplib,ssl; s=smtplib.SMTP('smtp.gmail.com',587); s.starttls(context=ssl.create_default_context()); s.login('me@gmail.com','APP_PASSWORD'); print('ok')"Confirmed by support.google.com
How do I stop it coming back?
- Keep the app password or OAuth token in an environment variable or a secret store, never in the repository.
- Pick one connection style per app: port 587 with STARTTLS, or port 465 with TLS from the start, and use a library that supports it.
- For new .NET code use MailKit instead of SmtpClient, which Microsoft no longer recommends.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Django send_mail fails or hangs with an SSL error
smtplib.SMTPException raised from send_mail()
Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).
4 causes, each with a fixSmtpException: Unable to read data from the transport connection (net_io_connectionclosed)
System.Net.Mail.SmtpException: Unable to read data from the transport connection: net_io_connectionclosed.
The server closed the connection while SmtpClient was waiting for a reply.
4 causes, each with a fixGmail SMTP blocks you with 454 4.7.0 Too many login attempts
SMTP Error: 454 4.7.0 Too many login attempts
454 4.7.0 is a temporary block.
2 causes, each with a fixGmail SMTP login fails with 535 or 534 5.7.14
534-5.7.14 Please log in via your web browser and then try again.
Gmail turned your sign-in down.
3 causes, each with a fixPython IMAP OAuth login to a shared mailbox in Microsoft 365 fails
imaplib.IMAP4.error: AUTHENTICATE failed.
Exchange Online accepts an OAuth token for IMAP only if the SASL user name is right and the token's identity has access to that mailbox.
4 causes, each with a fixPython says module smtplib has no attribute SMTP
print(smtplib.__file__) shows a path inside your own project
Python found a different smtplib than the standard one.
2 causes, each with a fix