Skip to content

Mail client TLS handshake fails: certificate mismatch or STARTTLS errors on cPanel

A mail client refuses to connect with a TLS or certificate error to a cPanel server. The cause is a hostname mismatch, missing AutoSSL, or an outdated protocol — here is the fix.

A mail client that throws “the certificate is not valid,” “cannot verify server identity,” or a STARTTLS failure is refusing to trust the encrypted connection to your cPanel server. The mailbox and password are irrelevant here — the client never gets far enough to log in, because the TLS layer underneath the IMAP or SMTP session did not satisfy it. On cPanel this is almost always one of three things: the client connects to a hostname the certificate does not cover, the mail certificate is self-signed or expired because AutoSSL did not issue one, or the client and server cannot agree on a TLS protocol version. Each has a clean fix once you see which certificate the server actually presents.

What’s happening

Every modern mail connection wraps IMAP/POP3/SMTP in TLS, either implicitly (ports 993/995/465) or by upgrading a plaintext session with STARTTLS (ports 143/110/587). During the handshake the server presents a certificate, and the client verifies two things: that the certificate is issued by a trusted CA and not expired, and that its subject (or a SAN entry) matches the hostname the client connected to. If the client is set to mail.example.com but the server only has a valid certificate for the cPanel host’s FQDN (server.host.net), verification fails on the name even though encryption itself would work.

cPanel issues mail certificates through AutoSSL, which covers the service hostnames it manages — typically the server FQDN and, when configured, the per-domain mail.example.com. When AutoSSL has not run, has been blocked (a failing DCV check), or the domain was added after the last run, the service falls back to a self-signed certificate that no client trusts. Separately, hardening that disables TLS 1.0/1.1 can break very old clients that never learned TLS 1.2 — a less common but real cause of handshake failures after a security update.

How to verify

Look at exactly what certificate the server presents on the port the client uses. This single command settles most cases.

# IMAPS (993): what cert, for what name, valid until when?
openssl s_client -connect mail.example.com:993 -servername mail.example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

# SMTP submission with STARTTLS (587):
openssl s_client -connect mail.example.com:587 -starttls smtp -servername mail.example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -dates

If the subject/SAN does not include the hostname the client uses, or issuer is the server itself (self-signed), or the dates are expired, you have found it. Confirm AutoSSL’s view of the mail service certificates:

# What cert is installed for the mail service?
whmapi1 fetch_service_ssl_components

# AutoSSL run log and any DCV failures
tail -50 /var/cpanel/logs/autossl_check.log

Check whether a protocol mismatch is in play (relevant only for old clients):

# Which TLS versions does the submission port accept?
openssl s_client -connect mail.example.com:587 -starttls smtp -tls1_2 </dev/null 2>/dev/null | grep -i 'protocol\|cipher'

# cPanel's configured minimum TLS protocol for mail
grep -i 'openssl_options\|tls_min' /etc/exim.conf.localopts

Watch the server side log a rejected handshake while the client tries:

tail -f /var/log/maillog | grep -i 'tls\|ssl\|starttls'

The fix

  1. Point the client at the certificate’s real hostname — the most common fix. From the openssl output, note the hostname the certificate actually covers (often the cPanel server FQDN). Set the client’s incoming and outgoing server fields to that exact name. cPanel » Email Accounts » Connect Devices shows the SSL-correct hostname for each mailbox — use it verbatim and the name check passes.

  2. Reissue the mail certificate with AutoSSL — if the server is presenting a self-signed or expired cert, run AutoSSL for the account: WHM » SSL/TLS » Manage AutoSSL » Run AutoSSL For All Users (or for the one user). If it fails, the autossl_check.log names the DCV problem — usually the mail. subdomain has no DNS record or the document root is unreachable. Fix that, then re-run so a trusted certificate covers mail.example.com.

  3. Add the mail subdomain to DNS so AutoSSL can cover it — AutoSSL can only secure mail.example.com if that hostname resolves. Confirm an A/CNAME for mail.example.com exists in WHM » DNS Zone Manager; without it, AutoSSL skips the name and clients using mail. hit a mismatch.

  4. Use the correct port and encryption mode — a client set to STARTTLS on an implicit-TLS port (or vice versa) fails the handshake. Use 993 IMAP SSL/TLS, 995 POP3 SSL/TLS, 465 SMTP SSL/TLS, or 587 SMTP STARTTLS. Do not mix “SSL/TLS” with port 587 or “STARTTLS” with 993.

  5. Re-enable a modern TLS version for old clients, or update the client — if the handshake fails only on a legacy device after a hardening change, the server likely requires TLS 1.2+. The right answer is to update the client; only as a temporary measure adjust the minimum protocol in WHM » Exim Configuration Manager and the Dovecot SSL config, and plan to remove that exception.

  6. Replace a self-signed cert that AutoSSL cannot reach with a manual Let’s Encrypt issuance — if AutoSSL is blocked for a reason you cannot fix immediately (DNS hosted elsewhere mid-migration), install a valid certificate for the mail hostname manually so clients stop seeing self-signed.

After reissuing or repointing, re-run the openssl s_client check and confirm a trusted issuer, a matching subject, and a future expiry — then the client connects without warnings. A TLS error is the server proving its identity and the client declining the proof; fix the identity and the connection opens. Stack Harbor manages cPanel mail certificates and AutoSSL under cPanel/WHM management — start a conversation.