# Postfix Recipient Checks

URL: https://email-validation.org/docs/guides/postfix/
Updated: 2026-11-25

> Documentation index: https://email-validation.org/llms.txt

A policy service for Postfix mail servers that checks the recipients of the mail your users send out, while it is
being submitted. By default it only logs each result: its answer to Postfix is always "carry on", so it never refuses
a recipient unless you turn that on. When a check cannot be made in time, the API answers with an error or the service
is not running, Postfix carries on and the mail goes out as usual. It never asks Postfix to delay mail.

It has two parts: **ev-policy**, a small daemon (Python 3 standard library, no packages) that Postfix asks through
its policy protocol (`check_policy_service`) over a Unix socket, and one line for your `main.cf`. Download them as one zip:
[ev-policy-1.0.0.zip](https://email-validation.org/downloads/postfix/ev-policy-1.0.0.zip), which unpacks into a folder `ev-policy/`. Postfix 3.0 or later.

## What gets checked

Only outbound mail: the client logged in (SMTP AUTH), or connects from one of your own servers that you list in
`outbound_networks`. Recipients at your own domains are not checked: the ones Postfix delivers or relays for, read
from `postconf` when the service starts, and any you list in `local_domains` (add the domains Postfix keeps in a
lookup table, such as virtual mailbox domains in a database: the service names those parameters when it starts).
Mail from other servers to your users is never checked, nor are messages submitted with the `sendmail` command.

## Set it up

1. Create an API key for the server on the [API keys page](https://email-validation.org/app/api-keys/) with the permission **Validate
   addresses** and a [daily credit cap](https://email-validation.org/docs/authentication/#limits).
2. Put the key in `/etc/ev-policy/api-key` without showing it: as root in bash, run `install -d -m 0755 /etc/ev-policy`
   and `(umask 077; read -rs -p 'API key: ' key && printf '%s\n' "$key" > /etc/ev-policy/api-key; echo)`, then
   paste the key at the prompt (it is not shown and stays out of your shell history). Then copy `ev_policy.py` to
   `/usr/local/lib/ev-policy/` and `ev-policy.conf` to `/etc/ev-policy/`, set `outbound_networks` to your relay
   hosts' networks, then run `python3 -I /usr/local/lib/ev-policy/ev_policy.py --check-config`.
3. Install `ev-policy.socket` and `ev-policy.service` in `/etc/systemd/system/` and run
   `systemctl enable --now ev-policy.socket`. The socket is created in Postfix's queue directory, so a chrooted smtpd
   reaches it, and only Postfix can connect to it. The key stays readable by root only: systemd hands the service
   its own copy. That needs systemd 247 or later; on an older systemd (RHEL and AlmaLinux 8 have 239), create a
   system user `ev-policy` that owns the key file, and in `ev-policy.service` replace `LoadCredential=` and
   `DynamicUser=` with `User=ev-policy`.
4. Add the line as the first entry of `smtpd_recipient_restrictions` in `/etc/postfix/main.cf`, above what is there:

   ```
   smtpd_recipient_restrictions =
       check_policy_service { unix:private/ev-policy, timeout=5s, default_action=DUNNO, try_limit=1 }
       ...the entries you already have...
   ```

   First, so that no `permit` above it ends the list for the mail it is meant to see; it never answers "accept", so
   it cannot open a relay there. The settings in braces apply to this check only and keep mail moving when the
   service cannot answer. If a service in `master.cf` (often `submission`) has its own list, give it the check
   through a named list in `main.cf` (a plain `-o` line would break at the spaces):

   ```
   # /etc/postfix/main.cf
   ev_submission_recipient_restrictions =
       check_policy_service { unix:private/ev-policy, timeout=5s, default_action=DUNNO, try_limit=1 }
       permit_sasl_authenticated
       reject

   # /etc/postfix/master.cf, in that service's entry
     -o smtpd_recipient_restrictions=$ev_submission_recipient_restrictions
   ```

   `postfix/main.cf.ev-policy` in the zip explains each setting in the braces.

5. Run `postfix check`, then `postfix reload`, and try a test address without sending a message:
   `swaks --auth … --quit-after RCPT` against port 587 ends the session after `RCPT TO`, so the check runs and nothing is sent.

Try it on a test server before a production one.

[Test addresses](https://email-validation.org/docs/test-addresses/) on `sandbox.email-validation.org` return the result their name says, cost nothing and
contact no mail server, so you can see every mode work before you spend a credit. Never send a whole message to one:
log mode lets every message go out (reject mode too, for a status it does not refuse), and the bounce would hurt your
server's sender reputation.

## Modes

| Mode | Set | What happens |
|---|---|---|
| Log (default) | nothing | a log line per checked recipient (`check rcpt=… status=invalid reason=no_mailbox source=api reply=dunno`) |
| Reject | `mode = reject` | as log, and a recipient whose status is in `reject_statuses` (default `invalid` and `disposable`) is refused with a `5xx` text you can edit |
| Header | `add_header = yes` | as the mode says, and an `X-EV-Recipient-Status` header for each status among the message's checked recipients |

Reject mode is off by default, because a refused recipient is mail that does not go out and no check is perfect.
It refuses only the statuses you list, never a recipient that could not be checked (nor an `unknown` result that only
says our side could not finish the check: reason `timeout` or `internal_error`), and the other recipients still get
the message. Your user sees the refusal at once in their mail program instead of a bounce later. Turn it on when
protecting your server's sending reputation matters more: mail to addresses that do not exist is what mailbox
providers count against a server.

The header costs nothing, but a header belongs to the whole message: every copy carries it, local deliveries and Bcc
recipients included, so it tells each recipient the statuses of the others, even ones they cannot see. Use it only on
a relay with no local mailboxes, for a filter that reads it.

## What it costs

Each check the service sends costs at most 1 credit, as with any [validation request](https://email-validation.org/docs/api/validate/); `unknown`
results, errors, malformed addresses and test addresses are free. A check of an address checked before also costs 1
credit ([repeat checks](https://email-validation.org/docs/api/validate/#repeat-checks)), so the service keeps its own cache, and an answer from it
costs nothing. Credits come in one-time [packs](https://email-validation.org/pricing/), as little as $0.15 per 1,000 with the
50,000,000-credit pack (smaller packs cost more per credit), and new accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service).

Four limits bound what it spends:

- **The cache**: each result is reused until its time is up (30 days for `valid` and `disposable`, 7 days for
  `invalid` and `catch_all`, 30 minutes for `unknown`). An `unknown` that only says our side could not finish the
  check is not kept.
- **Per sender**: 30 checks at once, then 120 an hour, for each sender (the login, else the relay host's IP
  address). Past that, their recipients go out unchecked, so a hijacked account spends at most that much of your
  credits before its checks stop.
- **Per day**: at most 1,000 checks a day (UTC) for all senders together, kept across restarts; once it is used up,
  every recipient goes out unchecked until the next day.
- **The key's daily credit cap**, which the API enforces whatever happens on your server.

Every limit can be changed in `/etc/ev-policy/ev-policy.conf`.

## Privacy

The service sends each outside recipient's address, and nothing else of the message, in the body of a `POST` to
`https://api.email-validation.org` (or `https://api-eu.email-validation.org` with `region = eu`, see [EU data residency](https://email-validation.org/docs/eu-data-residency/)), never in a URL and to no other
host. Its cache holds a keyed hash of each address, never the address, and its log never holds the API key or an
address: recipients and senders appear as short hashes, with Postfix's queue id.

## When something fails

Every failure is answered "carry on", and the log line's reason says why: `pending` (the API had not answered within
3 seconds: the check finishes in the background and is cached for the next message), `slow_api`, `sender_limit`,
`daily_cap`, `busy`, `api_limit` (the API asked to slow down; the service waits as long as `Retry-After` says),
`no_credits`, `key_refused`, `api_error`, `timeout` or `network_error`. When the service itself is stopped or does not
answer within 5 seconds, Postfix carries on by itself (`default_action=DUNNO`). After an answer that later checks
would get too, such as a refused key or no credits left, the service stops calling the API for a while instead of
slowing every message down. To switch it all off at once, run `systemctl stop ev-policy.socket ev-policy.service`.
If the service fails to start 3 times within 60 seconds (a key file it cannot read, a wrong setting), systemd stops
starting it and stops the socket, and Postfix carries on without checks. Fix the cause (`journalctl -u ev-policy`
says it), then run `systemctl reset-failed ev-policy.service ev-policy.socket` and
`systemctl start ev-policy.socket`.

## Related

- [Exim](https://email-validation.org/docs/guides/exim/)
- [Statuses and reasons](https://email-validation.org/docs/statuses/)
- [Rate limits](https://email-validation.org/docs/rate-limits/)

## More on Postfix

- [Postfix integration](https://email-validation.org/integrations/postfix/)
