New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
SMTP and APIUpdated 4 Nov 2026

STARTTLS versus implicit TLS: ports 587, 465 and 25 explained

How STARTTLS and implicit TLS differ, which SMTP port to use for each job, why port 25 is for server-to-server mail, and how to test and troubleshoot TLS connections with OpenSSL.

KW
Written by Kenji Watanabe
HTML Email Developer
Reviewed by Chloe Bennett
  • Published22 Jul 2023
  • Read time7 min
  • Length1,334 words
Share this guide

For an application sending mail to a relay, use port 465 with implicit TLS or port 587 with STARTTLS, and always authenticate. Both encrypt the session. They differ in when encryption starts: implicit TLS begins with a TLS handshake the moment the TCP connection opens, while STARTTLS opens a plain SMTP conversation and upgrades it with the STARTTLS command. Port 25 is the port for server-to-server delivery and is commonly blocked for ordinary clients.

This guide explains how each mode works on the wire, why RFC 8314 now prefers implicit TLS for mail submission, what downgrade risk means, and how to test and fix connection problems. Settings below for MigoSMTP are the relay host smtp.migosmtp.com on 587 (STARTTLS) and 465 (implicit TLS).

Port 465Implicit TLS. Encrypted from the first byte. Preferred for submission by RFC 8314
Port 587Submission with STARTTLS. Plain greeting, then upgrade. Widely supported
Port 25Server-to-server relay, usually opportunistic STARTTLS. Often blocked for clients
RuleNever send credentials before TLS is established

The two ways to encrypt SMTP

SMTP was designed without encryption. TLS was added later in two different ways, and the history explains the confusing port numbers. STARTTLS (RFC 3207) is an extension that lets a client and server begin in plain text and upgrade. Implicit TLS, historically called SMTPS, wraps the whole connection in TLS from the start, like HTTPS. Port 465 was first assigned to SMTPS, then reassigned, and then restored for message submission over implicit TLS by RFC 8314. That is why older articles call 465 deprecated and newer ones recommend it.

How STARTTLS works

S: 220 smtp.example.com ESMTP ready
C: EHLO client.example.org
S: 250-smtp.example.com
S: 250-STARTTLS
S: 250 AUTH PLAIN LOGIN
C: STARTTLS
S: 220 Ready to start TLS
   ... TLS handshake happens here ...
C: EHLO client.example.org
S: 250-smtp.example.com
S: 250 AUTH PLAIN LOGIN
C: AUTH PLAIN ...

Note that the client must send EHLO again after the handshake, because anything learned before encryption cannot be trusted. Only after that second EHLO should it authenticate. Servers that require TLS before authentication reply with a 530 error to clients that try to log in too early; see the 530 must issue STARTTLS first fix.

How implicit TLS works

With implicit TLS, the client connects to port 465 and the TLS handshake starts immediately. Only after it completes does the server send its 220 greeting, and everything, including the banner and EHLO, is inside the encrypted channel. There is no upgrade step, so there is nothing for an attacker to strip. In most libraries this is a single flag (often called secure, ssl or SMTPS) and it must not be combined with a STARTTLS setting.

Ports at a glance

PortRoleEncryptionWho uses it
25Server-to-server relay (MTA to MTA)Opportunistic STARTTLS, sometimes noneMail servers. Many ISPs and clouds block outbound 25 from ordinary hosts
587Message submission (RFC 6409)STARTTLS, required by well-run serversApplications and mail clients
465Message submission over implicit TLS (RFC 8314)TLS from the first byteApplications and mail clients
2525 and othersProvider-specific alternatesVariesCheck your provider's documentation

For a wider comparison with provider advice, see which SMTP port to use.

Which should you choose

  1. If your library and provider support both, choose 465 with implicit TLS. It removes the downgrade window and matches current guidance.
  2. If your environment only works with the traditional pairing, use 587 with STARTTLS and configure the client to require the upgrade rather than try it.
  3. Use 25 only when you run a mail server delivering to other domains, not from an application.
  4. Never choose a setting that falls back to plain text without telling you. In libraries this appears as options such as opportunistic, optional or ignoreTLS; avoid them for authenticated sending.
  5. Verify the server certificate name and chain. Disabling certificate checks to make an error disappear removes the protection you wanted.

The downgrade problem

STARTTLS begins in plain text, so an attacker on the path can remove the 250-STARTTLS line from the server's reply. A client that is willing to continue without encryption will then send its data and possibly its password in the clear. This is a STRIPTLS attack. Two defences apply. For clients, require TLS (fail the connection if the upgrade is not offered). For server-to-server mail, domain owners can publish MTA-STS or DANE so that sending servers know encryption is mandatory; see MTA-STS and TLS-RPT and DANE for SMTP. Implicit TLS has no such window for client submission.

Testing the connection with OpenSSL

Test each mode from the machine that will send. These commands show the certificate chain and let you type SMTP commands by hand.

# STARTTLS on 587
openssl s_client -starttls smtp -crlf -connect smtp.migosmtp.com:587 -servername smtp.migosmtp.com

# Implicit TLS on 465
openssl s_client -crlf -connect smtp.migosmtp.com:465 -servername smtp.migosmtp.com

# Check plain reachability of a port
nc -vz smtp.migosmtp.com 587

Look for Verification: OK or Verify return code: 0 (ok) and read the certificate subject and expiry. After the handshake, type EHLO test to confirm the server lists the authentication mechanisms. More test recipes, including swaks, are in testing an SMTP connection.

Certificates, versions and what encryption does not cover

Encryption is only useful if the client knows who it is talking to. During the handshake the server presents a certificate, and a properly configured client checks that the certificate chains to a trusted authority, has not expired and names the host that was requested. That is why you should connect using the provider's documented hostname rather than an IP address, and why a custom hostname pointing at a relay can produce a name mismatch error. Self-signed certificates on internal test servers need to be explicitly trusted in the client, never globally disabled.

On protocol versions, TLS 1.2 and TLS 1.3 are the modern baseline, and the older SSL and TLS 1.0 and 1.1 versions are deprecated. Individual providers set their own minimums, so confirm them in current documentation. If an old appliance, printer or legacy application fails the handshake, the right fix is an update or a local relay that speaks modern TLS to the internet, not a weaker server.

Remember what TLS covers. It protects the hop between two systems. It does not encrypt the message end to end, because each relay decrypts and re-encrypts, and the final mailbox provider can read the content. Content encryption needs S/MIME or PGP, covered in email encryption options. Likewise, TLS does not authenticate the sender domain. That is the job of SPF, DKIM and DMARC.

Configuration examples

# Python, implicit TLS on 465
import smtplib, ssl
ctx = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.migosmtp.com', 465, context=ctx) as s:
    s.login('USERNAME', 'PASSWORD')

# Python, STARTTLS on 587
with smtplib.SMTP('smtp.migosmtp.com', 587) as s:
    s.starttls(context=ctx)
    s.login('USERNAME', 'PASSWORD')

Both examples use the default context, which verifies the certificate against the system trust store. The username and password are the SMTP credentials from your account, not your login password.

Troubleshooting

SymptomLikely causeFix
Timeout or connection refusedFirewall or provider blocks the portTest with nc; try the other port; see connection and TLS errors
wrong version number or unknown protocolSTARTTLS client connected to an implicit TLS port, or the reverseMatch mode to port: 465 secure on, 587 STARTTLS
530 Must issue a STARTTLS command firstLogin attempted before upgradeEnable STARTTLS in the client
Certificate verify failedHostname mismatch, expired or missing intermediate, old CA bundleConnect by the exact hostname; update the trust store
Handshake failureClient supports only old protocol versionsUpdate the library and OS; TLS 1.2 or newer is the modern baseline
Works from laptop, fails from serverServer network blocks outbound portsAsk the host about egress rules for 587 and 465
Authentication fails after TLS succeedsWrong credentials or mechanismRe-enter SMTP credentials; see SMTP submission

Summary and next steps

Pick 465 with implicit TLS when you can and 587 with mandatory STARTTLS when you must, keep certificate verification on, and keep port 25 for servers. Test with OpenSSL before you blame the application. Port availability and accepted protocol versions on any given provider can change, so confirm them in that provider's current documentation.

Connect on 587 or 465 Send with TLS and authentication through smtp.migosmtp.com.

View the SMTP relay

References and further reading

Frequently asked questions

What is the difference between STARTTLS and SSL/TLS on SMTP?

STARTTLS upgrades a plain connection to TLS with a command, while SSL/TLS (implicit TLS) encrypts from the first byte of the connection.

Should I use port 587 or 465?

Either is fine if TLS is required. Current guidance in RFC 8314 prefers 465 with implicit TLS, and 587 with STARTTLS remains widely supported.

Why is port 25 blocked?

Many networks block outbound port 25 from ordinary hosts to limit spam from infected machines; it is meant for server-to-server mail.

Is STARTTLS less secure than implicit TLS?

It can be, because an attacker can strip the upgrade offer unless the client requires TLS. Requiring TLS removes that risk for submission.

How do I test SMTP TLS?

Run openssl s_client with -starttls smtp for port 587, or connect directly for port 465, and check that certificate verification succeeds.

Topics#tls#starttls#ports#smtp#encryption
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales