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).
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
| Port | Role | Encryption | Who uses it |
|---|---|---|---|
| 25 | Server-to-server relay (MTA to MTA) | Opportunistic STARTTLS, sometimes none | Mail servers. Many ISPs and clouds block outbound 25 from ordinary hosts |
| 587 | Message submission (RFC 6409) | STARTTLS, required by well-run servers | Applications and mail clients |
| 465 | Message submission over implicit TLS (RFC 8314) | TLS from the first byte | Applications and mail clients |
| 2525 and others | Provider-specific alternates | Varies | Check your provider's documentation |
For a wider comparison with provider advice, see which SMTP port to use.
Which should you choose
- If your library and provider support both, choose 465 with implicit TLS. It removes the downgrade window and matches current guidance.
- 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.
- Use 25 only when you run a mail server delivering to other domains, not from an application.
- 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.
- 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 587Look 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
| Symptom | Likely cause | Fix |
|---|---|---|
| Timeout or connection refused | Firewall or provider blocks the port | Test with nc; try the other port; see connection and TLS errors |
| wrong version number or unknown protocol | STARTTLS client connected to an implicit TLS port, or the reverse | Match mode to port: 465 secure on, 587 STARTTLS |
| 530 Must issue a STARTTLS command first | Login attempted before upgrade | Enable STARTTLS in the client |
| Certificate verify failed | Hostname mismatch, expired or missing intermediate, old CA bundle | Connect by the exact hostname; update the trust store |
| Handshake failure | Client supports only old protocol versions | Update the library and OS; TLS 1.2 or newer is the modern baseline |
| Works from laptop, fails from server | Server network blocks outbound ports | Ask the host about egress rules for 587 and 465 |
| Authentication fails after TLS succeeds | Wrong credentials or mechanism | Re-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.
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.