SMTP
No TCP socket ever opened to your SMTP host. Verify the host and port, test with telnet or openssl, and match STARTTLS on 587 or implicit TLS on 465.
Updated Jul 1, 2026
The short answer
"SMTP error: connection to server failed" is a transport-level failure: your mail client could not open a TCP socket to the SMTP host, so no SMTP conversation ever began. It is not an RFC 5321 reply code. The usual causes are a wrong host/port, an ISP, firewall, or cloud security group blocking outbound SMTP, or a TLS mode mismatch. Fix it by verifying the host and port, testing connectivity with telnet/openssl, and matching STARTTLS (587) or implicit TLS (465).
This error appears in client libraries like PHPMailer ("SMTP connect() failed" / "Failed to connect to server"), Nodemailer (ECONNREFUSED, ETIMEDOUT), and Python smtplib. It means your application tried to open a TCP socket to the SMTP host and failed before any email protocol exchange happened — the server never returned the 220 greeting that RFC 5321 §3.1 requires to start a session. Because the failure is at the network/transport layer, the message is not a standard 3-digit SMTP reply code; treat it as a connectivity problem, not a mail-content or authentication rejection.
ENCRYPTION_STARTTLS+587 or ENCRYPTION_SMTPS+465 — don't mix them.# STARTTLS porttelnet smtp.example.com 587# implicit TLS port — should print the 220 greeting and a certopenssl s_client -connect smtp.example.com:465
If telnet/openssl hang or are refused, the problem is a firewall, ISP, security group, or host block — fix the network path, not your code.
$mail->SMTPDebug = SMTP::DEBUG_SERVER;, Nodemailer { logger: true, debug: true } — to see exactly where the socket fails.If you're sending through Courier, you don't manage SMTP sockets directly — configure your email provider in the Courier dashboard and Courier handles the connection, retries, and TLS to the provider's API/SMTP endpoint.
References
FAQ
No. It's a transport-level (TCP socket) failure raised by your mail client before any SMTP dialogue starts, so the server never sends the 220 greeting. It is not one of the 3-digit reply codes defined in RFC 5321 — treat it as a network/connectivity problem, not a mail rejection.
One API, every provider
Courier connects to your email, SMS, and push providers, handles retries and failover, and surfaces delivery errors in plain language.
Reply-code definitions per RFC 5321 §3.1. Last reviewed Jul 1, 2026. Courier is not affiliated with third-party providers; error behavior may vary by implementation.
© 2026 Courier. All rights reserved.