# SMTP: [SSL: WRONG_VERSION_NUMBER] wrong version number — SMTP over SSL on a STARTTLS port

**Code:** `SSL: WRONG_VERSION_NUMBER (SMTP port)` · **Category:** Email / SMTP · **Seen on:** SMTP, Python, Linux

Your client tried to start TLS immediately on a port where the server speaks plain SMTP first (or the reverse), so the handshake looks garbled.

## Meaning

Port 465 uses implicit TLS (SSL from the first byte); port 587 starts plain and upgrades with STARTTLS. Mixing them gives `wrong version number`, `packet length too long` or `unexpected EOF`. Match the connection mode to the port.

## Common causes

- SSL/TLS enabled on port 587 (should be STARTTLS)
- STARTTLS used on port 465 (should be implicit SSL)
- Port 25 with TLS wrapper mode
- A proxy or antivirus intercepting SMTP
- Server not offering TLS at all

## Quick fix

1. Port 587 → STARTTLS (`secure: false` in Nodemailer, `SMTP()` + `starttls()` in Python)
2. Port 465 → implicit TLS (`SMTP_SSL`, `secure: true`)
3. Test with openssl first

## Detailed fix by platform

### Linux

1. `openssl s_client -starttls smtp -connect smtp.example.com:587` (STARTTLS) vs `openssl s_client -connect smtp.example.com:465` (implicit)

## Code examples

### Correct per port

```python
import smtplib
# 587: plain connect, then upgrade
s = smtplib.SMTP("smtp.example.com", 587); s.starttls()
# 465: TLS from the start
s2 = smtplib.SMTP_SSL("smtp.example.com", 465)
```

## How to diagnose

1. **Port** — 465 or 587?
2. **Mode** — SSL or STARTTLS?
3. **Proxy** — AV or proxy in between?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/email/ssl-wrong-version-number-smtp)
