Join our Newsletter — 33% off our NHI Course
Home› Guides› Exim and Postfix Mail Server Hardening Guide: Closing…
Guide Email & Communications Security

Exim and Postfix Mail Server Hardening Guide: Closing Relays, Securing SMTP AUTH and Patching Fast

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 14 min read
On this page

A self-hosted mail transfer agent is an internet-facing parser of untrusted input that often runs with root privileges, so careful configuration and prompt patching matter. Exim and Postfix still carry a large share of internet mail, either as the MX for organisations that run their own mail, as outbound relays for applications, or buried inside appliances and control panels. A misconfigured MTA becomes an open relay, a password-spraying target or a remote code execution foothold. This guide covers the identity and privilege model of both MTAs, relay and SMTP AUTH controls, TLS, the credentials applications use to submit mail, logging and detection, and a hardening baseline with exact parameter names. It is for Linux administrators, email engineers and the security teams who review them. For the wider email programme (gateways, DMARC, phishing) see the Email Security Guide.

This is an independent guide from NHI Mgmt Group, based on the Exim and Postfix projects' public documentation as of November 2026. It is not sponsored or reviewed by the Exim or Postfix projects. Product features change, so confirm settings against the Exim and Postfix projects' current documentation.

Key takeaways

  • Relay control is the first check, not an afterthought. In Postfix 2.10 and later, smtpd_relay_restrictions must end in reject_unauth_destination; in Exim, the RCPT ACL decides relay, and an undefined acl_smtp_rcpt denies every recipient.
  • SMTP AUTH is an identity system. Only advertise it after TLS, bind envelope senders to login names, rate limit authentication, and treat every relay account an application uses as a non-human identity with an owner.
  • Patch quickly. Subscribe to the Exim security announcements and Postfix release announcements, and patch internet-facing MTAs on an emergency timeline.
  • Opportunistic TLS on the public MX, mandatory TLS everywhere else. Use may for inbound port 25, require TLS on submission and between your own relays, and use DANE or policy maps for partners who need guarantees.
  • The logs already tell you about abuse. Authentication failures, relay denials, sudden volume from one authenticated user and a non-empty Exim paniclog are high-value signals that most teams never forward to the SIEM.

How identity and access work in Exim and Postfix

Both MTAs separate a small privileged component from the processes that talk to the network, but they do it differently, and the difference shapes how you harden them.

AspectPostfixExim
Process modelMany small daemons managed by master; network-facing smtpd runs as the unprivileged postfix user, often chrooted per master.cfOne binary, normally setuid root; the daemon drops to the Exim user after opening sockets, but delivery and routing processes keep root unless deliver_drop_privilege is set
Who can relaysmtpd_relay_restrictions (2.10 and later), typically permit_mynetworks, permit_sasl_authenticated, reject_unauth_destinationThe RCPT ACL (acl_smtp_rcpt) using host lists such as relay_from_hosts, the authenticated condition and domains checks
Client authenticationSASL via Dovecot (smtpd_sasl_type = dovecot) or Cyrus (the default)Authenticator drivers (plaintext, Dovecot, Cyrus SASL and others) configured in the authenticators section
Local privileged usersroot for postfix commands; postdrop group for local submissionTrusted users (root, the Exim user, trusted_users, trusted_groups) can set sender information; admin users can manage the queue
Default that bitesOn releases before 2.10, HELO exceptions placed before reject_unauth_destination can create an open relayOther ACLs (connect, MAIL, DATA, AUTH) default to accept when undefined, so missing ACLs mean missing checks

The practical point: whichever MTA you run, know which code runs as root, keep that surface small with the options below, and patch promptly.

Admin roles and privileged access

  • Operating system administrators: whoever has root or sudo on the MTA host controls mail routing, can read every queued message and can harvest relay credentials from maps such as /etc/postfix/sasl_passwd. Put these accounts under your privileged access process, with named accounts and session logging. See the Linux Privilege Escalation Techniques Guide for what an attacker does with a foothold on a host like this.
  • Exim trusted and admin users: keep trusted_users and trusted_groups to the accounts that genuinely inject mail with arbitrary senders (for example a list manager). Admin users can freeze, thaw and remove queued messages. Set commandline_checks_require_admin so ordinary local users cannot run address-testing options, and leave prod_requires_admin and queue_list_requires_admin at their restrictive defaults.
  • Alternate configuration files: Exim's -C and -D options keep root only for root callers unless a file is in TRUSTED_CONFIG_LIST. Build with DISABLE_D_OPTION where packaging allows, and keep FIXED_NEVER_USERS including root so no delivery runs as root.
  • Configuration ownership: main.cf, master.cf and the Exim configuration should be root-owned and not writable by the MTA user. Spool files in Exim default to mode 0640 for the Exim group, so membership of that group is read access to mail.
  • Web control panels: hosting panels that manage Exim or Postfix are an admin interface to the MTA. Restrict them to management networks and require MFA, because a panel compromise rewrites mail routing without touching the MTA's own controls.

Integrations, API tokens and service accounts

Most MTAs that are not public MX hosts exist to relay mail for applications: monitoring, ticketing, printers, scanners, cron jobs and web apps. Each of these holds a credential or relies on an IP allowlist, and both are non-human identities.

Integration patternRiskControl
IP-based relay (mynetworks or Exim relay_from_hosts)Any process on any listed host can send as anyone; wide subnets turn one compromised server into a phishing relayList individual hosts, not /16 ranges; move applications to authenticated submission where possible
Shared SMTP AUTH account for many appsNo attribution, password sits in many config files, rotation breaks everything at onceOne account per application, owner recorded, secret held in a vault, rotation scheduled
Authenticated user can send as any addressA stolen app credential becomes a spoofing tool for executive addressesPostfix smtpd_sender_login_maps with reject_sender_login_mismatch; in Exim compare the sender to $authenticated_id in the MAIL or RCPT ACL
MTA authenticates outbound to a smarthost or cloud email APIRelay credential in smtp_sasl_password_maps is a direct route to send from your sending reputationRoot-only file permissions, postmap after each change, TLS required to the relay (smtp_tls_security_level = encrypt), scoped API keys at the provider
Cyrus sasldb2 user databaseStores passwords in plaintext according to the Postfix SASL documentationPrefer Dovecot or directory-backed authentication; if used, restrict file access to the postfix user

Inventory these accounts like any other machine credential: who owns it, which host uses it, when it was last rotated, and whether it still sends mail. See the SendGrid, Mailgun and Mailchimp API Keys Security Guide for the cloud relay side, and the TruffleNet campaign for how stolen sending credentials are turned into business email compromise at scale.

Relay, SMTP AUTH and TLS configuration

Postfix

  • Relay policy: smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination. Keep smtpd_recipient_restrictions for spam policy. smtpd_reject_unlisted_recipient = yes is the default and should stay.
  • Protocol hygiene: smtpd_helo_required = yes, reject_unknown_sender_domain in smtpd_sender_restrictions, and disable_vrfy_command = yes. Test strictness changes with soft_bounce = yes so mistakes defer rather than bounce.
  • SMTP AUTH: smtpd_sasl_auth_enable = yes only on the submission service (port 587, or 465 with implicit TLS), not on the public port 25 listener. Set smtpd_tls_auth_only = yes and smtpd_sasl_security_options = noanonymous (add noplaintext outside TLS).
  • Rate limits (anvil): smtpd_client_connection_count_limit defaults to 50; smtpd_client_connection_rate_limit, smtpd_client_message_rate_limit, smtpd_client_recipient_rate_limit and smtpd_client_auth_rate_limit (3.1 and later) default to no limit, over anvil_rate_time_unit of 60s. Set values that stop abuse without throttling legitimate peaks, and remember $mynetworks is exempt by default.
  • TLS server: smtpd_tls_security_level = may on the public MX (the Postfix documentation warns against encrypt on a publicly referenced server), encrypt on submission. Use smtpd_tls_chain_files (3.4 and later), smtpd_tls_mandatory_protocols = >=TLSv1.2 (3.6 and later) and smtpd_tls_loglevel = 1.
  • TLS client: smtp_tls_security_level = may as a baseline, dane where you run a local DNSSEC-validating resolver, and smtp_tls_policy_maps to require verify or secure for named partners.

Exim

  • Relay policy: keep the RCPT ACL structure from the distribution default: accept from +relay_from_hosts, accept authenticated = *, require recipient verification for local domains, and deny everything else for non-local domains. Remember an ACL that runs off its end denies.
  • Advertise AUTH only under TLS: on each server authenticator set server_advertise_condition = ${if eq{$tls_in_cipher}{}{no}{yes}}, and record the login with server_set_id so $authenticated_id appears in logs. auth_advertise_hosts defaults to all hosts.
  • Rate limits: use the ratelimit ACL condition keyed on $authenticated_id for submission and on the client IP for unauthenticated sessions.
  • Privilege: set deliver_drop_privilege where your delivery design allows (it restricts pipe and file deliveries), and avoid use_shell on pipe transports, which the Exim documentation flags as a shell injection risk.
  • Disabled commands: VRFY, EXPN and ETRN are disabled unless an ACL enables them. Leave them off.

For the protocol side of STARTTLS, downgrade attacks and MTA-STS see the SMTP Security, STARTTLS and MTA-STS Guide.

Logging and detection

Postfix logs through syslog (commonly /var/log/maillog or the journal); Exim writes mainlog, rejectlog and paniclog under $spool_directory/log/ unless log_file_path points elsewhere. Forward both to the SIEM with the host name preserved.

SignalWhere it showsWhat it can meanATT&CK
Bursts of SASL authentication failures from one IP or across many accountsPostfix smtpd warnings for failed SASL logins; Exim authenticator failures and $authenticated_fail_idPassword spraying against submissionT1110.003 Password Spraying
Successful AUTH followed by high recipient counts or new destination domainsPostfix sasl_username= on smtpd lines; Exim A= on <= linesCompromised account or app credential used for spam or phishingT1078 Valid Accounts
Relay denied for external recipients from an internal hostPostfix "Relay access denied" rejects; Exim rejectlogCompromised internal host trying to send, or a misconfigured appT1071.003 Mail Protocols
Malformed or unusual RCPT addresses, protocol errorsExim with log_selector = +smtp_protocol_error +smtp_syntax_errorScanning or exploitation attempts against parser flawsT1190 Exploit Public-Facing Application
Non-empty Exim paniclog, MTA crashes, new child processes of the MTApaniclog; EDR or auditd process eventsCrash during exploitation or post-exploitation command executionT1068, T1505 Server Software Component
Changes to main.cf, master.cf, Exim configuration, transport maps or new forwarding rulesFile integrity monitoring, auditdMail redirection or blind copy to an attackerT1114.002 Remote Email Collection

Useful Exim selectors beyond the defaults: +tls_peerdn +incoming_interface +smtp_incomplete_transaction +smtp_connection. In Postfix, smtpd_tls_received_header = yes records TLS details in headers, and smtp_tls_note_starttls_offer = yes logs remote servers that offered STARTTLS, which helps when tightening outbound policy. See the Linux Logging and auditd for Defenders Guide for host-level monitoring.

Metrics that show the controls work:

  • Days from an Exim or Postfix security release to deployment on internet-facing hosts (target: within your critical patch window).
  • Number of relay accounts and allowlisted hosts with a named owner, as a share of the total (target: 100 percent).
  • Relay accounts rotated within policy in the last 12 months.
  • Share of outbound sessions to top partner domains that used verified TLS.
  • Authentication failure rate per day and number of rate-limit triggers, trended for anomalies.
  • External open relay tests passed after every configuration change (target: always passing).

Hardening baseline

  1. Inventory first. Find every MTA, including ones bundled in appliances, hosting panels and container images. Record version, role (MX, submission, internal relay), exposure and owner. Check versions against the Exim security advisories and your distribution's errata.
  2. Patch and subscribe. Move to a supported release, subscribe to Exim and Postfix announcements, and put internet-facing MTAs in the emergency patching path. See the Emergency Out-of-Band Patching Playbook.
  3. Split roles. Public MX accepts mail only for your domains and offers no AUTH. Submission (587 or 465) requires TLS and AUTH. Internal relays listen only on internal interfaces.
  4. Apply relay and AUTH settings from the section above in a test instance, with soft_bounce = yes for Postfix during the change window.
  5. Test before cutover. Run external open relay tests, send from an authenticated account to an external domain, attempt AUTH before STARTTLS (it must not be offered), and confirm sender mismatch rejection.
  6. Restrict the host. Firewall management ports to admin networks, allow 25 inbound only on MX hosts and 587 or 465 only where clients need it. See the Linux Firewall Guide.
  7. Move credentials to a vault and rotate relay passwords; remove shared accounts.
  8. Forward logs and set alerts for the signals in the detection table.
  9. Roll back safely. Keep the previous configuration under version control; postfix check and postconf -n (Postfix) or exim -bV (Exim) validate syntax before reload, and a reload with the old files restores service.

Small versus large organisations: a small organisation with no reason to self-host the MX should consider whether a managed email service removes the patching burden, keeping only an internal relay for devices. Large organisations with many relays benefit from one configuration managed in code, with relay accounts provisioned automatically and rotated centrally.

Framework mapping

Control areaNIST SP 800-53 Rev. 5NIST CSF 2.0CIS Controls v8.1ISO/IEC 27001:2022 Annex A
Relay restrictions, least functionalityCM-7, SC-7PR.PS-01Control 4, Control 9A.8.9, A.8.21
SMTP AUTH and relay credentialsIA-5, AC-6PR.AAControl 5, Control 6A.5.17, A.8.2
TLS for mail transportSC-8PR.DSControl 3A.5.14, A.8.24
Patching the MTASI-2ID.RA-01, PR.PS-02Control 7A.8.8
Spam and abuse filteringSI-8DE.CM-01Control 9A.8.23
Logging and reviewAU-2, AU-6DE.CM-01Control 8A.8.15, A.8.16

Common misconfigurations

  • Running an outdated MTA on the internet. Apply security updates promptly, as listed in the Exim security announcements and on the Postfix home page, including MTAs inside hosting estates and appliances. See the CISA KEV Catalogue Guide.
  • Wide mynetworks or relay_from_hosts. Allowlisting a whole data centre range means a single compromised web server can relay phishing that passes your SPF.
  • AUTH on port 25 or before TLS. Offering plaintext AUTH without TLS exposes passwords, and AUTH on the public MX gives spraying tools a target they do not need.
  • No sender binding. An authenticated account that can send as the chief executive is a ready-made BEC tool. See the Email Identity and BEC Guide.
  • Mandatory TLS on the public MX. Setting smtpd_tls_security_level = encrypt on port 25 rejects mail from legitimate senders without TLS; use MTA-STS and DANE for assurance instead.
  • Logs left on the box. When the MTA is the compromised host, local logs are the first thing an attacker edits. Forward them before you need them.

Practitioner checklist

  • Inventory every Exim and Postfix instance, including appliances and panels, with version, role and owner.
  • Confirm internet-facing MTAs are on a supported release and in the emergency patch path.
  • Verify relay policy ends in reject_unauth_destination (Postfix) or a deny for non-local domains (Exim), and run an external open relay test.
  • Offer SMTP AUTH only on submission ports and only after TLS.
  • Bind envelope senders to authenticated logins.
  • Give each application its own relay credential, stored in a vault, with an owner and rotation date.
  • Narrow IP-based relay lists to individual hosts.
  • Set anvil or ratelimit limits on connections, recipients and authentication attempts.
  • Forward MTA logs to the SIEM and alert on authentication bursts, relay denials and paniclog entries.
  • Keep MTA configuration in version control with syntax checks before reload.

Standards and references

Related NHI Mgmt Group resources: Email Security Guide · SMTP Security, STARTTLS and MTA-STS Guide · DMARC, SPF and DKIM Guide · SendGrid, Mailgun and Mailchimp API Keys Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.