Smtp

"The SMTP server requires a secure connection": causes and fixes

Short answer

The error "The SMTP server requires a secure connection or the client was not authenticated" means the server answered 530: it wants TLS and a login before it accepts mail. In .NET, set EnableSsl = true, use port 587 (SmtpClient cannot do implicit TLS on 465), set UseDefaultCredentials = false before Credentials, and log in with an app password or API key rather than an account password.

Last checked 16 November 2026

The full message is usually “The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.” It comes from .NET’s System.Net.Mail.SmtpClient, and it means the server answered with a 530: it wants TLS and a successful login before it accepts mail. One of those two did not happen.

The four usual causes

  1. TLS is off. EnableSsl is false, so the client never sent STARTTLS.
  2. Wrong port for the TLS mode. SmtpClient only supports STARTTLS. On port 465, which expects TLS from the first byte, it cannot connect properly.
  3. Credentials were not sent. UseDefaultCredentials = true was set after Credentials, which wipes them, or no credentials were set at all.
  4. The login was refused. Gmail and Yahoo reject account passwords from apps, and Microsoft 365 may have SMTP AUTH turned off.

Fix it in C# with SmtpClient

using System.Net;
using System.Net.Mail;

using var client = new SmtpClient("smtp.example.com", 587)
{
    EnableSsl = true,                 // sends STARTTLS
    UseDefaultCredentials = false,    // must come before Credentials
    Credentials = new NetworkCredential("user@example.com", Environment.GetEnvironmentVariable("SMTP_PASSWORD")),
    DeliveryMethod = SmtpDeliveryMethod.Network,
};

client.Send("user@example.com", "sam@example.com", "Test", "It works.");

The key details:

  • Port 587, not 465. Microsoft’s EnableSsl documentation says SmtpClient only supports STARTTLS as defined in RFC 3207, and that the SSL-on-connect method on port 465 “is not currently supported.”
  • UseDefaultCredentials = false first. Setting it to true replaces your credentials with the Windows login.
  • The right password. For Gmail, an app password. For Yahoo, an app password. For Microsoft 365, a mailbox with SMTP AUTH enabled, and OAuth where possible.

Microsoft also no longer recommends SmtpClient for new code and points to MailKit, which supports both STARTTLS and implicit TLS:

using MailKit.Net.Smtp;
using MailKit.Security;

using var smtp = new SmtpClient();
await smtp.ConnectAsync("smtp.example.com", 465, SecureSocketOptions.SslOnConnect);
// or: await smtp.ConnectAsync("smtp.example.com", 587, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync("user@example.com", Environment.GetEnvironmentVariable("SMTP_PASSWORD"));
await smtp.SendAsync(message);
await smtp.DisconnectAsync(true);

Checking what the server actually wants

If the fixes above do not help, talk to the server by hand to see which step fails. From the machine that runs your app:

openssl s_client -connect smtp.example.com:587 -starttls smtp -crlf -quiet

Then type EHLO test. The reply lists the extensions the server offers after TLS, including the AUTH methods it accepts, such as AUTH LOGIN PLAIN XOAUTH2. If AUTH only lists XOAUTH2, the server wants OAuth and a password will never work. If the openssl command itself fails, the problem is the network or TLS version, not your credentials.

The same error in other tools

The wording differs, but the cause is the same 530:

Where Message Fix
Gmail 530 5.7.0 Must issue a STARTTLS command first Turn on STARTTLS, or use 465 with SSL
Microsoft 365 530 5.7.57 Client not authenticated to send mail Log in, with TLS 1.2 or later
PHPMailer SMTP Error: Could not authenticate Match SMTPSecure to the port and fix the password
Python smtplib SMTPNotSupportedError: SMTP AUTH extension not supported by server Call starttls() before login()
Printers “Server requires a secure connection” Enable SSL/TLS or STARTTLS, update firmware

Many servers only advertise AUTH after TLS starts. That is why skipping starttls() in Python shows up as “AUTH not supported” rather than a TLS error. RFC 4954 defines the related codes: 530 for authentication required, 535 for invalid credentials, 538 for encryption required.

“SMTP server unavailable”

This one is different: the client never got a reply. Common wordings are “Failure sending mail,” “Unable to connect to the remote server,” “Connection timed out” and “SMTP connect() failed.”

Work through it in order:

  1. Host name. Check spelling, and that it resolves: nslookup smtp.example.com.
  2. Port reachable. From the same machine, run nc -vz smtp.example.com 587. A timeout means a firewall or your hosting provider is blocking it. Cloud hosts commonly block port 25; see the SMTP ports guide.
  3. TLS mode matches the port. Implicit TLS on 587 or STARTTLS on 465 hangs and then times out, which looks like “unavailable.”
  4. Server status. Check the provider’s status page.

SMTP queue not sending, or relay queue stuck

If your app hands mail to a local mail server (Postfix, Exim, an IIS SMTP service or Exchange) and nothing arrives, the messages are sitting in its queue, deferred after a failed delivery attempt. The queue keeps the last error for each message, which is the fastest route to the cause.

On Postfix:

mailq                      # list queued messages and the reason each is deferred
postqueue -f               # retry everything now, after you fix the cause
postsuper -d ALL deferred  # delete deferred mail, only if you are sure

Common reasons in the deferral text:

  • Connection timed out to the relay host: outbound port blocked.
  • 530 or 535: the relay needs authentication and the local server is not configured with credentials and TLS.
  • 421 or 451: the remote side is throttling. Mail will retry on its own.
  • 550 or other 5xx: permanent. These bounce rather than wait. See the SMTP error codes guide.

Flushing a queue without fixing the cause just repeats the failure.

Avoiding it altogether

Most of these errors come from personal mailbox providers tightening login rules. Microsoft 365, for example, is turning off Basic auth for SMTP by default at the end of December 2026.

If the sender is your own app, a transactional relay that accepts an API key over TLS avoids OAuth and app passwords. Mailcandor’s SMTP relay runs on smtp.mailcandor.com, port 587 (STARTTLS, which works with SmtpClient) or 465 (implicit TLS), with username mailcandor and an API key as the password.

Questions

What does 'the SMTP server requires a secure connection' mean?

The server replied with a 530 code: it will not accept mail until the client starts TLS and logs in. Either TLS was off, the login was missing, or the login was rejected.

Why does it fail on port 465 with EnableSsl = true?

System.Net.Mail.SmtpClient only supports STARTTLS. Microsoft's documentation says the SSL-on-connect method used on port 465 is not supported, so use port 587, or switch to MailKit.

I set EnableSsl and credentials but still get the error with Gmail. Why?

Gmail rejects your account password from apps. Create an app password (2-Step Verification must be on) and use that. Also make sure UseDefaultCredentials is set to false before you assign Credentials.

What does 'SMTP server unavailable' mean?

Your app could not open a connection to the server at all. The host name is wrong, the port is blocked by a firewall or your host, or the server is down. It is a network problem, not an authentication one.

How do I clear a stuck SMTP queue?

Find out why messages are deferred first (read the queue's last error), fix that, then flush. On Postfix, mailq shows the queue and postqueue -f retries everything.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.