Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Gmail rejects your mail with 530 5.5.1 Authentication Required

ErrorThe SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

Short 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.

  • Applies to .NET 8, Python 3.12, smtp.gmail.com
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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"))
    PY
  2. 2Match what you see, then jump to its fix

    1. 1The server answers 530 right after MAIL FROM, and your code has no credentials or no login call.The app never signs inFix
    2. 2In 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. 3Authentication 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

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 Required
  • 530 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

Did this fix it?

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/null

Confirmed by learn.microsoft.com

Did this fix it?

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

Did this fix it?

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:

Related fixes

Email

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.