Errors

SSL "wrong version number" on SMTP: the 465 vs 587 mix-up

Short answer

"wrong version number" is an OpenSSL error. On SMTP it almost always means your client started a TLS handshake on a port where the server first speaks plain text, typically port 587 or 25, which use STARTTLS. The reply looked nothing like TLS, so OpenSSL complained about the version. Fix it by using implicit TLS only on port 465 and STARTTLS on 587: secure true for 465 and false for 587 in Nodemailer, SMTP_SSL for 465 and starttls() for 587 in Python.

Last checked 16 November 2026

SSL wrong version number on SMTP almost always means your client and the server disagree about when encryption starts. Your app began a TLS handshake immediately, but the server on that port expected plain SMTP first, then STARTTLS. The usual culprit is implicit TLS settings pointed at port 587. Match the mode to the port and it goes away.

The error message

The text comes from OpenSSL, so it looks similar in every language. Python’s smtplib:

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number

Node.js (Nodemailer and others), where the error code is ERR_SSL_WRONG_VERSION_NUMBER:

Error: error:0A00010B:SSL routines::wrong version number

OpenSSL 1.1.1 and older print ssl3_get_record:wrong version number instead. PHP, Ruby and curl show the same OpenSSL reason.

What it means

Every TLS record starts with a version field. When your client sends a TLS ClientHello to a port that speaks plain SMTP, the server answers with a text greeting such as 220 smtp.example.com ESMTP. OpenSSL reads those bytes as a TLS record header, finds a “version” that makes no sense, and stops with wrong version number. OpenSSL’s reason code for this is SSL_R_WRONG_VERSION_NUMBER.

The two SMTP encryption modes:

Port Mode How it starts
465 Implicit TLS TLS handshake first, then SMTP inside it.
587 STARTTLS Plain SMTP, the client sends STARTTLS, then TLS starts.
25 STARTTLS (optional) Server to server delivery; often blocked for apps.

Why it happens

  • Implicit TLS on port 587: secure: true in Nodemailer, SMTP_SSL in Python, ssl in PHPMailer or Laravel with port 587.
  • Implicit TLS on port 25.
  • A proxy or antivirus on the network intercepting SMTP and answering in plain text.
  • A server that does not offer TLS on that port at all.

The reverse mistake, plain SMTP or STARTTLS on port 465, usually shows up as a timeout or a closed connection rather than this error. See SMTP connection timed out.

How to fix it

  1. Pick one combination and set both sides of it.
  2. Nodemailer: the SMTP docs say to set secure: true for port 465, and for port 587 or 25 to leave it false and let STARTTLS upgrade the connection.
    nodemailer.createTransport({ host: 'smtp.mailcandor.com', port: 587, secure: false,
      auth: { user: 'mailcandor', pass: process.env.MAILCANDOR_KEY } });
  3. Python: the smtplib docs say SMTP_SSL is for situations where SSL is required from the beginning of the connection. Use SMTP_SSL on 465, and SMTP plus starttls() on 587:
    import os, smtplib
    with smtplib.SMTP("smtp.mailcandor.com", 587) as s:
        s.starttls()
        s.login("mailcandor", os.environ["MAILCANDOR_KEY"])
  4. PHPMailer: SMTPSecure = 'ssl' (or PHPMailer::ENCRYPTION_SMTPS) with port 465, 'tls' (ENCRYPTION_STARTTLS) with 587.
  5. Laravel and other frameworks: set the encryption or scheme setting to match the port in the same way.
  6. Test by hand to see what the server expects:
    openssl s_client -connect smtp.example.com:465 -quiet
    openssl s_client -starttls smtp -connect smtp.example.com:587 -quiet

Which server sent it

None. This is a client-side TLS error raised before any SMTP reply. It is the same against Gmail, Microsoft 365, Yahoo or any relay, because it depends only on how your client connects. If the server did answer with a code, such as Gmail’s 530 5.7.0 Must issue a STARTTLS command first, see STARTTLS errors.

Is it temporary?

No. It fails the same way every time until the configuration changes. Retrying is pointless; fix the port or the mode.

How Mailcandor handles it

Mailcandor’s SMTP relay accepts both modes on smtp.mailcandor.com: port 465 with TLS and port 587 with STARTTLS, username mailcandor and an API key as the password. Or skip SMTP and use the email API over HTTPS. For delivery errors after sending, the deliverability coach explains bounces in plain English, and hard bounces are suppressed automatically. Look up SMTP codes with the free bounce code lookup, or browse all error codes. More free checks are on the tools page. To make sure your own domain is authenticated, follow the SPF, DKIM and DMARC setup guide.

Questions

What causes SSL wrong version number in SMTP?

Your client tried TLS straight away on a port that expects plain SMTP followed by STARTTLS. The server's plain text greeting is not a valid TLS record, and OpenSSL reports it as a wrong version number.

Which port should I use, 465 or 587?

Either works if the client mode matches. 465 is implicit TLS: encrypted from the first byte. 587 starts in plain text and upgrades with STARTTLS. Both end up encrypted.

How do I fix it in Nodemailer?

Nodemailer's docs say to set secure: true for port 465, and leave secure: false for port 587 or 25 so STARTTLS upgrades the connection.

Is it a certificate problem?

No. Certificate problems produce errors like certificate verify failed or hostname mismatch. Wrong version number means the two sides disagree about whether TLS has started.

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.