What Is a Secure Email Server and How Do You Set One Up?

Diagram of email delivery from sending app to recipient, showing TLS, STARTTLS, MTA-STS, SPF, DKIM, DMARC, and inbound spam filtering.
For beginners

Your mail server sends invoices, password resets, and customer updates all day. Yet if a single setting is wrong, a stranger may be able to send email that looks like it came from your domain. Or your own messages can start going to spam folders.

A secure email server lowers these risks, and each setting handles a different one. TLS encryption protects mail while it moves between systems. Access control limits which users and apps can send through your server. SPF, DKIM, and DMARC let receiving servers check whether a message that uses your domain came from a sender you’ve authorized. No single control stops every attack, and the receiving server always decides what happens to each message.

Each protection has its own setup and often its owner. One team manages the server, another handles domain settings, and developers own the app that sends the mail. Problems arise when nobody checks how these pieces fit together. This guide explains how a secure email server works, which controls to set up first, and how to check them. It also covers which parts an email provider can manage for you.

What Is a Secure Email Server?

A secure email server is set up to protect each step of a message’s journey. It encrypts connections and verifies senders. It also limits who can use the server and filters incoming mail.

No single setting does all of that. Each protection covers one part of the path a message takes, so start by mapping that path. It has three stages:

Submission: A mail app or application connects to your server and hands over a message using Simple Mail Transfer Protocol (SMTP). RFC 8314 recommends Transport Layer Security (TLS) version 1.2 or higher for this connection. Without it, your sensitive message can cross the network in plain text.

Server-to-server transfer: Your server finds the recipient’s mail server through the Domain Name System (DNS) query and delivers the message over SMTP. This hop usually starts in plain text and upgrades to encryption with a special command called STARTTLS. 

RFC 8461 describes the weakness: an attacker who strips the STARTTLS offer can force the message to travel unencrypted. SMTP MTA Strict Transport Security (MTA-STS) addresses this. The receiving domain publishes a policy that tells supporting senders to refuse delivery when encryption fails.

This stage is also where the receiving server checks who sent the message. Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM), and Domain-based Message Authentication, Reporting and Conformance (DMARC) let the receiving server check whether a sender is the one you’ve authorized to send the message. The receiving server then checks the message for spam, phishing, and malware.

Mailbox access: The recipient reads the message in one of two ways. A mail client, such as Outlook or Thunderbird, connects to the mailbox over Internet Message Access Protocol (IMAP). RFC 8314 recommends TLS 1.2 or higher for this connection, with implicit TLS on port 993 preferred. Webmail works differently. The browser connects to the webmail interface over HTTPS, which protects traffic between the browser and the webmail server.

The diagram below marks where each control applies.

Diagram of email delivery from sending app to recipient, showing TLS, STARTTLS, MTA-STS, SPF, DKIM, DMARC, and inbound spam filtering.

How to Secure an Email Server

Configure all of these controls in the order below. Each step names the threat it addresses and gives one check that confirms it works. Run the check right after the change and note who owns it.

Protect Mail Transport and Authenticate Your Domain

Start with encryption, then publish the DNS records that prove who you are.

  1. Install a valid TLS certificate. The threat is an attacker who intercepts or impersonates your server. Use a certificate from a public certificate authority with a name that matches your mail hostname. Test it with openssl s_client -connect mail.example.com:465 -verify_hostname mail.example.com -verify_return_error. 

The -verify_hostname option checks that the certificate matches your mail hostname, while -verify_return_error stops the connection if certificate verification fails. To test port 587, change the port and add -starttls smtp. Expected result: the handshake completes, the output shows “Verified peername: mail.example.com”, and it ends with “Verify return code: 0 (OK).”

  1. Require encryption for submission. The threat is passwords and messages crossing the network in clear text. Use implicit TLS on port 465, which RFC 8314 prefers, or STARTTLS on port 587 with encryption required. Your server software’s documentation names the exact setting. Expected result: the server does not offer login until the session is encrypted.
  2. Publish an MTA-STS policy for inbound mail. The threat is an attacker downgrading incoming server-to-server connections to plain text. RFC 8461 defines a testing mode and an enforce mode. In testing mode, sending servers that support MTA-STS can still deliver mail when policy validation fails, for example, when your certificate does not match a host listed in your policy. They do not enforce the policy, but senders that support TLS-RPT can report the failure.

To receive these reports, publish a TLS-RPT DNS record, defined in RFC 8460. Participating senders then send you summaries of TLS connections to your domain, including failures. Review these reports, investigate the problems they reveal, and resolve any configuration issues before switching to enforce.

In enforce mode, senders refuse to deliver over connections that fail the policy checks. This MTA-STS guide covers the DNS record, the policy file, and the certificate requirements. Expected result: TLS-RPT reports from participating senders show no unresolved configuration issues. A test message that arrives over verified TLS confirms only that one delivery worked.

  1. Publish an SPF record. The threat is anyone sending mail that claims to come from your domain. List every server and service that sends for you and end the record with ~all or -all. Some receiving servers may reject a message that fails SPF before they check DMARC, even if aligned DKIM would have passed. Messages rejected this way never appear in DMARC aggregate reports. Keep the record under the 10 DNS lookup limit in RFC 7208. Expected result: a test message shows “spf=pass” in its headers.
  2. Sign outgoing mail with DKIM. The threat is a forged message or one altered in transit. Generate a key pair, publish the public key in DNS, and have the server sign every outgoing message. Expected result: a test message shows “dkim=pass” with a signing domain that matches your From domain.
  3. Publish a DMARC record and raise enforcement in stages. The threat is a spoofed message reaching inboxes under your From domain. Start with p=none and read the aggregate reports. Fix any legitimate sender that fails, then move to quarantine and later reject. DMARC passes when SPF or DKIM passes with a domain that aligns with the From domain, as RFC 9989 explains. Expected result: reports show your known sources passing, and a spoofed test message fails.

Example: a spoofed invoice. Someone sends an invoice that shows [email protected] in the From line, from a server you do not control. Neither SPF nor DKIM passes with a domain that matches your From address, so DMARC fails. 

The receiving server checks your published DMARC policy, which specifies how you want failing mail handled: none, quarantine, or reject. However, the receiving server makes the final decision based on its own rules. A message that fails DMARC can still be delivered, sent to spam, or rejected.

The header of that message would look like this, with placeholder domains:

Authentication-Results: mx.recipient.example;

 spf=pass smtp.mailfrom=attacker.example;

 dkim=none;

 dmarc=fail header.from=yourcompany.com

SPF passes for the attacker’s own domain, but that domain does not match your From address, so it does not count toward DMARC.

Restrict Access and Filter Mail

Next, control who can send through your server and what reaches your users.

  1. Close open relay. The threat is spammers sending through your server and getting your IP address blocklisted. Accept mail from unauthenticated clients only for domains you host. Expected result: from a machine outside your network, connect on port 25 and send a RCPT TO for an address at a domain you do not host. The server answers with a 5xx rejection such as “relay access denied.”
  2. Turn on multi-factor authentication (MFA) and apply least privilege. The threat is a stolen password used to send mail. Require MFA for webmail and admin accounts. SMTP login cannot prompt for a second factor (2FA), so give each application its own credentials. Remove accounts nobody uses. Expected result: a login without the second factor fails, and each credentials can do only its own job.
  3. Restrict ports and patch on a schedule. The threat is an attacker exploiting an unused open port or outdated software. Allow only the ports you use: 25 for server-to-server mail, 465 or 587 for submission, 993 for IMAP over TLS, and 443 if you run webmail. Expected result: a port scan from outside shows only those ports, and the server runs the vendor’s latest security release.
  4. Set outbound rate limits. The threat is a compromised account sending thousands of messages before anyone notices. Limit the number of messages per account, per hour and per connection. Expected result: a test account that passes the cap is throttled or blocked, and the event appears in the logs.
  5. Filter inbound mail. The threat is spam, phishing, and malware reaching mailboxes. Turn on scanning on the server, or place a secure email gateway in front of it, and check SPF, DKIM, and DMARC on incoming messages. Expected result: an EICAR test attachment, a harmless file that antivirus tools treat as a virus, should be quarantined or rejected.

How to Verify and Maintain Email Server Security

Test every control after you configure it, and test it again on a schedule. Give each check a named owner, such as the mail admin, the domain admin, or the application team. A control without an owner can fail unnoticed.

Read your authentication headers: Send a test message to an outside mailbox and open the full headers. A message that passes SPF, DKIM, and DMARC shows lines like these (actual domains replaced by example.com):

Authentication-Results: mx.recipient.example;

 spf=pass smtp.mailfrom=example.com;

 dkim=pass header.d=example.com;

 dmarc=pass header.from=example.com

If any line says fail or none, re-check to the matching step above.

Test your relay controls: Repeat the open relay test after every configuration change. From an outside machine, an unauthenticated message to an outside address should draw a rejection like this:

RCPT TO:<[email protected]>

554 5.7.1 <[email protected]>: Relay access denied

The wording varies by server software, but the 5xx code is the signal. Run this only against servers you own or have permission to test.

Monitor these signals after launch:

  • Unknown sources failing alignment in DMARC reports (owner: domain admin)
  • TLS delivery errors and certificate expiry dates (owner: mail admin)
  • Failed logins and logins from new locations (owner: mail admin)
  • Queue size and bounce rate (owner: mail admin)
  • Outbound volume per account against its rate limit (owner: application team)
  • Blocklist status of your sending IP addresses (owner: mail admin)

Investigate a sending spike: A spike can come from a legitimate app release or from a stolen credential. Check before you revoke anything.

  1. Review authentication logs for logins from unfamiliar IP addresses or a burst of failed attempts.
  2. Check the queue for rapid growth and bounces, and see which account sent the messages.
  3. Compare the volume with that account’s rate limit. If one credential caused the spike and the pattern looks abusive, revoke and replace it, then clear the spam from the queue.

Plan for recovery: Back up mailboxes, server configuration, and DKIM private keys. Restore a backup to a test server on a schedule. Expected result: a restored mailbox opens, and a test message from the restored server shows “dkim=pass.” Renew certificates before they expire, since expired ones cause TLS checks to fail.

Self-Hosted vs. Managed Email

You can run a secure email server yourself, move mailboxes to a hosting provider, or send application mail through an outbound relay. A relay is a service that delivers mail for your apps: the app hands over each message, and the relay sends it to the recipient. 

Each option changes who maintains each security control, such as encryption, sender authentication, and access. The table shows who owns what.

ControlSelf-hosted serverHosted mailboxesOutbound SMTP relay
Inbound mail and filteringYouProviderNot covered
Mailbox logins and MFAYouProvider runs the platform, you set user policyNot covered
Outbound sending and queuesYouProviderRelay provider
TLS, certificates, and patchingYouProviderRelay provider, for its own servers
SPF, DKIM, and DMARC recordsYouYou, using values from the providerYou, using values from the relay
Sending credentialsYouYou manage accountsYou create and rotate API keys

A “Not covered” value means the service does not handle that part of the mail path. An outbound relay, for example, sends mail but does not care for your inbound mail or host inboxes.

Every option leaves DNS records and user access with you, so the checks from the earlier steps still apply to those parts even when a provider runs the servers.

Example: password resets from an app. Say your staff use mailboxes at a hosting provider, and your app needs to send password reset emails. The app connects to a relay such as UniOne, which sends them for it.

  1. A user clicks “Forgot password” in your app.
  2. The app sends the reset email to the relay over an encrypted SMTP connection on port 465 or 587, using its own credentials.
  3. The relay delivers the email to the user’s mail provider.

Your mailbox provider keeps hosting employee inboxes. Both services now send mail under your domain, so your DNS has to authorize both. Put them in one SPF record, since a domain can have only one. Each service also signs its mail with its own DKIM key, so publish both keys.

Conclusion

A secure email server depends on several controls working together. Encrypt connections and authenticate your domain with SPF, DKIM, and DMARC. Limit who can send through the server, filter incoming messages for spam and malware, and keep the software patched. Each control addresses a different risk, so test them regularly and assign someone to own each check.

If you’d rather not manage outbound email delivery yourself, an SMTP relay such as UniOne can handle it. Your application connects to the relay over an encrypted SMTP connection, while the service manages the sending infrastructure for your transactional email. You still need to verify your sending domain by publishing the required DNS records and manage access to your SMTP credentials.

Ready to get started? Try UniOne’s SMTP relay for your application’s outbound email. 

Frequently Asked Questions

How do I check if my mail server is an open relay?

Test from a machine outside your network. Connect to your server on port 25 and send MAIL FROM command with any address. Then send RCPT TO for an outside address you own, at a domain you do not host. Stop before sending any message data. A secure server rejects the recipient with a 5xx error such as “relay access denied.” If it accepts the recipient, fix your relay rules at once and check your IP address against blocklists.

Does SMTP TLS encrypt email end to end?

No, TLS protects a message only while it travels between two systems, such as your server and the recipient’s. Each server that handles the message can store it unencrypted. Also, if STARTTLS fails and the sender allows a fallback, that hop can travel in plain text, which is why MTA-STS matters. End-to-end encryption needs S/MIME or OpenPGP, and both the sender and the recipient have to have it set up.

Can I use an SMTP relay with my existing business mailboxes?

Yes. Staff keep using their current mailboxes for daily mail and for anything inbound, and your applications send through the relay instead. Add the relay to your SPF record, publish its DKIM key, and keep one DMARC record that covers both senders. Send a test message from each and confirm that SPF or DKIM passes with a domain that matches your From address.

When should I move DMARC from monitoring to enforcement?

Move when your aggregate reports show every legitimate sender passing with alignment. Fix any failing source first, such as a forgotten billing tool or a marketing platform. Then switch from p=none to p=quarantine and keep reading the reports. Move to p=reject once they stay clean.

How often should I check my email server security?

Run the authentication header test and the open relay test after every configuration change. Review DMARC reports, logs, and queue activity on a set schedule, and check certificate expiry dates well before renewal. Test a backup restore on a schedule too. Give each check an owner so none gets skipped.

Related Articles
10 Best ActiveCampaign Alternatives for Businesses
Blog
For beginners
10 Best ActiveCampaign Alternatives for Businesses
ActiveCampaign is a well-known email marketing platform, but not necessarily the best choice for anyone. We review 10 best alternatives to ActiveCampaign for each type of business.
Alexey Kachalov
Alexey Kachalov
12 september 2024, 11:31
10 Best Free SMTP Servers for Transactional and Marketing Emails
Blog
For beginners
10 Best Free SMTP Servers for Transactional and Marketing Emails
We reviewed the top SMTP servers offering free usage to help you choose the right one for your email delivery without breaking the bank!
Vitalii Piddubnyi
Vitalii Piddubnyi
05 june 2026, 12:00
10 Best Mailgun Alternatives For Transactional Emails
Blog
For beginners
10 Best Mailgun Alternatives For Transactional Emails
Choose the right Mailgun alternative for bulk and transactional emailing and scale your email capabilities.
Valeriia Klymenko
Valeriia Klymenko
20 march 2026, 12:17