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_restrictionsmust end inreject_unauth_destination; in Exim, the RCPT ACL decides relay, and an undefinedacl_smtp_rcptdenies 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
mayfor 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.
| Aspect | Postfix | Exim |
|---|---|---|
| Process model | Many small daemons managed by master; network-facing smtpd runs as the unprivileged postfix user, often chrooted per master.cf | One 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 relay | smtpd_relay_restrictions (2.10 and later), typically permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination | The RCPT ACL (acl_smtp_rcpt) using host lists such as relay_from_hosts, the authenticated condition and domains checks |
| Client authentication | SASL 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 users | root for postfix commands; postdrop group for local submission | Trusted users (root, the Exim user, trusted_users, trusted_groups) can set sender information; admin users can manage the queue |
| Default that bites | On releases before 2.10, HELO exceptions placed before reject_unauth_destination can create an open relay | Other 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_usersandtrusted_groupsto the accounts that genuinely inject mail with arbitrary senders (for example a list manager). Admin users can freeze, thaw and remove queued messages. Setcommandline_checks_require_adminso ordinary local users cannot run address-testing options, and leaveprod_requires_adminandqueue_list_requires_adminat their restrictive defaults. - Alternate configuration files: Exim's
-Cand-Doptions keep root only for root callers unless a file is inTRUSTED_CONFIG_LIST. Build withDISABLE_D_OPTIONwhere packaging allows, and keepFIXED_NEVER_USERSincluding root so no delivery runs as root. - Configuration ownership:
main.cf,master.cfand 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 pattern | Risk | Control |
|---|---|---|
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 relay | List individual hosts, not /16 ranges; move applications to authenticated submission where possible |
| Shared SMTP AUTH account for many apps | No attribution, password sits in many config files, rotation breaks everything at once | One account per application, owner recorded, secret held in a vault, rotation scheduled |
| Authenticated user can send as any address | A stolen app credential becomes a spoofing tool for executive addresses | Postfix 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 API | Relay credential in smtp_sasl_password_maps is a direct route to send from your sending reputation | Root-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 database | Stores passwords in plaintext according to the Postfix SASL documentation | Prefer 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. Keepsmtpd_recipient_restrictionsfor spam policy.smtpd_reject_unlisted_recipient = yesis the default and should stay. - Protocol hygiene:
smtpd_helo_required = yes,reject_unknown_sender_domaininsmtpd_sender_restrictions, anddisable_vrfy_command = yes. Test strictness changes withsoft_bounce = yesso mistakes defer rather than bounce. - SMTP AUTH:
smtpd_sasl_auth_enable = yesonly on the submission service (port 587, or 465 with implicit TLS), not on the public port 25 listener. Setsmtpd_tls_auth_only = yesandsmtpd_sasl_security_options = noanonymous(addnoplaintextoutside TLS). - Rate limits (anvil):
smtpd_client_connection_count_limitdefaults to 50;smtpd_client_connection_rate_limit,smtpd_client_message_rate_limit,smtpd_client_recipient_rate_limitandsmtpd_client_auth_rate_limit(3.1 and later) default to no limit, overanvil_rate_time_unitof 60s. Set values that stop abuse without throttling legitimate peaks, and remember$mynetworksis exempt by default. - TLS server:
smtpd_tls_security_level = mayon the public MX (the Postfix documentation warns againstencrypton a publicly referenced server),encrypton submission. Usesmtpd_tls_chain_files(3.4 and later),smtpd_tls_mandatory_protocols = >=TLSv1.2(3.6 and later) andsmtpd_tls_loglevel = 1. - TLS client:
smtp_tls_security_level = mayas a baseline,danewhere you run a local DNSSEC-validating resolver, andsmtp_tls_policy_mapsto requireverifyorsecurefor named partners.
Exim
- Relay policy: keep the RCPT ACL structure from the distribution default: accept from
+relay_from_hosts, acceptauthenticated = *, 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 withserver_set_idso$authenticated_idappears in logs.auth_advertise_hostsdefaults to all hosts. - Rate limits: use the
ratelimitACL condition keyed on$authenticated_idfor submission and on the client IP for unauthenticated sessions. - Privilege: set
deliver_drop_privilegewhere your delivery design allows (it restricts pipe and file deliveries), and avoiduse_shellon 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.
| Signal | Where it shows | What it can mean | ATT&CK |
|---|---|---|---|
| Bursts of SASL authentication failures from one IP or across many accounts | Postfix smtpd warnings for failed SASL logins; Exim authenticator failures and $authenticated_fail_id | Password spraying against submission | T1110.003 Password Spraying |
| Successful AUTH followed by high recipient counts or new destination domains | Postfix sasl_username= on smtpd lines; Exim A= on <= lines | Compromised account or app credential used for spam or phishing | T1078 Valid Accounts |
| Relay denied for external recipients from an internal host | Postfix "Relay access denied" rejects; Exim rejectlog | Compromised internal host trying to send, or a misconfigured app | T1071.003 Mail Protocols |
| Malformed or unusual RCPT addresses, protocol errors | Exim with log_selector = +smtp_protocol_error +smtp_syntax_error | Scanning or exploitation attempts against parser flaws | T1190 Exploit Public-Facing Application |
Non-empty Exim paniclog, MTA crashes, new child processes of the MTA | paniclog; EDR or auditd process events | Crash during exploitation or post-exploitation command execution | T1068, T1505 Server Software Component |
Changes to main.cf, master.cf, Exim configuration, transport maps or new forwarding rules | File integrity monitoring, auditd | Mail redirection or blind copy to an attacker | T1114.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
- 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.
- 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.
- 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.
- Apply relay and AUTH settings from the section above in a test instance, with
soft_bounce = yesfor Postfix during the change window. - 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.
- 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.
- Move credentials to a vault and rotate relay passwords; remove shared accounts.
- Forward logs and set alerts for the signals in the detection table.
- Roll back safely. Keep the previous configuration under version control;
postfix checkandpostconf -n(Postfix) orexim -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 area | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | CIS Controls v8.1 | ISO/IEC 27001:2022 Annex A |
|---|---|---|---|---|
| Relay restrictions, least functionality | CM-7, SC-7 | PR.PS-01 | Control 4, Control 9 | A.8.9, A.8.21 |
| SMTP AUTH and relay credentials | IA-5, AC-6 | PR.AA | Control 5, Control 6 | A.5.17, A.8.2 |
| TLS for mail transport | SC-8 | PR.DS | Control 3 | A.5.14, A.8.24 |
| Patching the MTA | SI-2 | ID.RA-01, PR.PS-02 | Control 7 | A.8.8 |
| Spam and abuse filtering | SI-8 | DE.CM-01 | Control 9 | A.8.23 |
| Logging and review | AU-2, AU-6 | DE.CM-01 | Control 8 | A.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
mynetworksorrelay_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 = encrypton 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
ratelimitlimits 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
- Postfix: SMTP Access Policy (SMTPD_ACCESS_README)
- Postfix: SASL Howto (SASL_README)
- Postfix: TLS Support (TLS_README)
- Postfix: Performance Tuning and Rate Limits (TUNING_README)
- Exim: Security Considerations (Exim Specification)
- Exim: Access Control Lists (Exim Specification)
- Exim: Log Files (Exim Specification)
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