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
- TLS is off.
EnableSslis false, so the client never sentSTARTTLS. - Wrong port for the TLS mode.
SmtpClientonly supports STARTTLS. On port 465, which expects TLS from the first byte, it cannot connect properly. - Credentials were not sent.
UseDefaultCredentials = truewas set afterCredentials, which wipes them, or no credentials were set at all. - 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
SmtpClientonly supports STARTTLS as defined in RFC 3207, and that the SSL-on-connect method on port 465 “is not currently supported.” UseDefaultCredentials = falsefirst. 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:
- Host name. Check spelling, and that it resolves:
nslookup smtp.example.com. - 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. - TLS mode matches the port. Implicit TLS on 587 or STARTTLS on 465 hangs and then times out, which looks like “unavailable.”
- 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 outto the relay host: outbound port blocked.530or535: the relay needs authentication and the local server is not configured with credentials and TLS.421or451: the remote side is throttling. Mail will retry on its own.550or 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.