MailSlurp logo

blog

SMTP encryption guide: TLS, STARTTLS, and secure SMTP setup

Understand SMTP encryption and how to secure mail transfer with TLS, STARTTLS, authentication, and domain alignment controls.

SMTP encryption guide: TLS, STARTTLS, and secure SMTP setup article preview

SMTP encryption protects an email while it travels across a network. The important bit is knowing which SMTP connection you are securing. An application submitting a password-reset email is not the same as one mail server relaying that message to another.

Get that boundary right and the rest becomes much less mysterious: require verified TLS for submission, protect credentials, publish transport policy for inbound relay, authenticate your sending domain, and test the message after it arrives.

Quick answer: what is SMTP encryption?

SMTP encryption uses TLS to protect an SMTP connection. For an application or email client submitting mail, use implicit TLS on port 465 or STARTTLS on port 587, following your provider's documented setting. In either case, the client must require a successful TLS handshake and validate the server certificate before it authenticates.

A secure SMTP server also limits who may submit or relay mail, protects authentication secrets, and records enough evidence to spot failures or abuse. Encryption is essential, but it is not the whole lock on the door.

Mail server to mail server delivery normally uses port 25. TLS there is often opportunistic: servers encrypt when they can, but ordinary STARTTLS alone can be downgraded. Recipient domains can add a mandatory policy with MTA-STS or DANE and collect failure reports with TLS-RPT.

First, identify the SMTP connection

There are three common paths. They may use the same protocol, but they should not share one copy-pasted security policy.

Application or email client to submission server

This is your website, worker, CRM, or desktop mail app handing a message to a provider. It normally uses:

  • Port 465 with TLS from the first byte, known as implicit TLS
  • Port 587 with a required STARTTLS upgrade
  • SMTP authentication after the encrypted connection is established

RFC 8314 recommends implicit TLS for message submission and keeps STARTTLS on port 587 for broad compatibility. Correct implementations of either mode offer comparable protection when they require TLS and validate the certificate. Do not put user credentials on port 25 just because an old snippet happens to connect.

Mail server to mail server

Mail transfer agents look up the recipient domain's MX records and normally connect on port 25. Public MX servers cannot simply reject every sender that lacks STARTTLS without breaking ordinary internet mail delivery. That is why relay commonly begins with opportunistic TLS.

Opportunistic TLS is useful, but its name is doing honest work: an attacker in the path may be able to remove the advertised STARTTLS capability and tempt a sender into a cleartext fallback. MTA-STS or DANE for SMTP gives supporting senders a policy they can use to resist that downgrade.

Internal relay

An internal relay might accept mail from a private network, an allowlisted workload, or an authenticated service. Treat the boundary explicitly. Restrict who can connect, restrict which destinations they can relay to, require TLS where the clients support it, and keep it from becoming an open relay with a very generous front door.

What TLS protects - and what it does not

TLS protects one network hop while that connection is active. It can provide confidentiality, integrity, and server authentication for that hop. A properly configured client can tell that it reached the named server and that traffic was not quietly rewritten in transit.

TLS does not make an email end-to-end encrypted. A message can be decrypted at an intermediate server, stored in a mailbox, scanned for abuse, forwarded, or relayed over another connection with different protection. S/MIME and OpenPGP address end-to-end message confidentiality; they solve a different problem.

TLS also does not prove that the visible From address is legitimate, guarantee inbox placement, or make unsafe HTML trustworthy. Those jobs belong to domain authentication, content controls, and delivery testing.

Secure SMTP setup checklist

Use this sequence when configuring a sender, changing providers, or checking a mail path that has acquired a few too many historical knobs:

  1. Confirm the hostname and use port 465 with implicit TLS or port 587 with required STARTTLS, exactly as the provider documents. If the TLS upgrade fails, fail the send instead of continuing in cleartext.
  2. Allow TLS 1.2 and 1.3; retire TLS 1.0 and 1.1 in line with RFC 8996.
  3. Validate the certificate chain, expiry, and hostname. Never make rejectUnauthorized: false your production fix.
  4. Authenticate only after TLS is active. Prefer a scoped token or OAuth where supported, store secrets outside source code, and revoke exposed credentials promptly.
  5. Permit relay only for authenticated or explicitly trusted clients and destinations.
  6. Send a harmless fixture through the same library and settings your application uses.
  7. Receive it in a MailSlurp Email Sandbox, then inspect the delivered headers, body, links, and attachments.
  8. Check SPF, DKIM, and DMARC results with the email header analyzer.
  9. Run an email deliverability test when inbox placement matters, because an SMTP 250 response is not an inbox receipt.

The SMTP tester can help confirm connection settings without turning production customers into test subjects. Keep the release check repeatable: same fixture, same assertions, and a fresh test inbox for each run.

Verify the TLS handshake yourself

OpenSSL is useful when a library reports only "connection failed" and leaves you to supply the detective music.

For STARTTLS on port 587:

openssl s_client \
  -starttls smtp \
  -connect smtp.example.com:587 \
  -servername smtp.example.com \
  -verify_hostname smtp.example.com \
  -verify_return_error

For implicit TLS on port 465:

openssl s_client \
  -connect smtp.example.com:465 \
  -servername smtp.example.com \
  -verify_hostname smtp.example.com \
  -verify_return_error

Replace the example hostname with the exact host your provider gave you. Check for all of the following:

  • Verify return code: 0 (ok)
  • A certificate whose subject alternative name covers the SMTP hostname
  • A complete, trusted certificate chain
  • A negotiated protocol of TLS 1.2 or 1.3
  • On port 587, an SMTP greeting followed by a successful STARTTLS handshake

These commands diagnose the connection; they do not need your password. Do not paste live credentials into an interactive debugging transcript or a support ticket.

Protect SMTP authentication

SMTP AUTH answers "may this client submit mail?" It is separate from TLS, although the two should be used together.

PLAIN and LOGIN do not independently encrypt a password. They are acceptable only inside a verified TLS connection. If your provider supports OAuth or short-lived tokens, those can reduce the damage caused by a leaked long-lived password, but they do not excuse a weak transport.

Give each application its own credential where possible. That makes it easier to revoke one compromised secret without interrupting every sender. Keep secrets in your deployment's secret store, exclude them from logs, and avoid placing them in URLs or shell history. Rate limits and source restrictions add useful guardrails for automated senders.

On the receiving side, reject unauthenticated relay. A public MX server accepts mail for its own domains; it should not act as a free onward courier for arbitrary destinations.

Make server-to-server TLS observable

Ordinary STARTTLS on port 25 improves privacy, but it does not automatically make TLS mandatory. Two complementary controls help recipient domains tighten and observe that path:

  • MTA-STS publishes, through DNS and HTTPS, which MX hosts are valid and whether supporting senders should require trusted TLS. Start with testing mode, inspect failures, then move to enforcement after every legitimate MX host is covered.
  • TLS-RPT publishes a reporting address in a _smtp._tls TXT record. Supporting senders can then deliver aggregate reports about successful TLS sessions and failures such as certificate, routing, or STARTTLS errors. RFC 8460 defines the format.

DANE is another route to authenticated, downgrade-resistant SMTP transport. It uses TLSA records secured by DNSSEC. Choose the mechanism your DNS and mail operations can run reliably; a half-maintained policy can delay legitimate mail.

MailSlurp DMARC monitoring complements transport reporting by keeping domain-authentication changes visible. TLS-RPT tells you about the encrypted road between mail servers. DMARC reports tell you who is using your domain identity. They are neighbors, not twins.

Domain authentication controls

SMTP security and deliverability improve when SPF, DKIM, and DMARC are configured correctly. None of them encrypts the message:

  • SPF authorizes hosts to send using a domain in the SMTP MAIL FROM or HELO identity. Forwarding can complicate the result.
  • DKIM lets a domain take responsibility for a cryptographic signature. Verification can detect changes to the signed headers or body; it does not prevent somebody from modifying a message, and it does not hide the content.
  • DMARC requires a passing SPF or DKIM identity to align with the domain visible in the From header. The current standard, RFC 9989, also defines domain policy and aggregate reporting.

Related tools:

Troubleshooting SMTP security issues

"Must issue STARTTLS first"

Enable STARTTLS in your SMTP client and confirm you are using the right host and port.

Also check whether the library treats TLS as optional. Settings named secure, requireTLS, starttls, and use_ssl are not interchangeable across languages. Match the setting to the provider's documented mode.

Certificate verification failed

Read the actual certificate error before changing anything. Common causes are an expired certificate, an incomplete intermediate chain, a hostname mismatch, a TLS-inspecting proxy, or a machine with an outdated trust store. Fix the cause. Disabling verification only converts a useful alarm into a quiet vulnerability.

Frequent auth failures

Verify the username format, account policy, app password or token, and supported authentication mechanism. Confirm that TLS completed before testing LOGIN or PLAIN. Repeated retries with the same bad secret can trigger throttling and make the original problem harder to see.

Mixed TLS support across systems

Separate the paths before comparing them. Submission on 465 or 587 should fail closed when TLS cannot be established. Public relay on 25 follows different interoperability rules; use MTA-STS or DANE for a published mandatory policy and TLS-RPT for failure visibility.

SMTP accepts the message but users do not see it

Separate transport acceptance from user-visible delivery. Send a test message to a MailSlurp inbox, wait for receipt, inspect headers and content, run spam checks, and compare placement across providers before releasing the change.

Messages started queueing after MTA-STS enforcement

Check that every legitimate MX host appears in the policy and presents a trusted certificate for its MX hostname. Review TLS-RPT failures before shortening timeouts or weakening the policy. A queue is often the messenger pointing at one forgotten host.

Frequently asked questions

Is SMTP port 465 better than 587?

Both can protect message submission. Port 465 starts TLS immediately and is preferred by RFC 8314; port 587 upgrades with STARTTLS and remains widely supported. Use the mode your provider documents, require TLS, and validate its certificate. A correctly configured 587 connection is safer than a misconfigured 465 connection with verification disabled.

Is port 25 insecure?

Port 25 is the normal port for mail server relay, not a password-submission port for applications. Relay can use STARTTLS, but the default internet model is often opportunistic. MTA-STS or DANE can make TLS policy downgrade-resistant for supporting senders.

Does STARTTLS encrypt the whole email journey?

No. STARTTLS protects the SMTP hop on which it is negotiated. A multi-hop delivery needs protection on each connection, and stored messages are outside that connection. Use end-to-end encryption when only the sender and intended recipient should be able to read the content.

Do SPF, DKIM, or DMARC replace TLS?

No. They authenticate domain use and publish handling policy; they do not encrypt message transport. A mature mail setup uses both transport security and domain authentication, then checks the message that recipients actually receive.

Final take

Secure SMTP is a chain of small, testable decisions: the right port, required modern TLS, a certificate you actually verify, a scoped credential, a relay that knows its boundaries, and domain records that agree with the visible sender.

Finish with a real delivery check. Create a free MailSlurp account, send through the same path your application will use, and inspect what arrived. That last hop from "the server accepted it" to "a person received the right email" is where a configuration becomes trustworthy.