Skip to content

whitelist

The whitelist filter accepts or refuses at three steps of the SMTP session, each driven by its own lists:

Step Lists Accepts when
connection ips, subnets, domains the client address matches ips or subnets, or its hostname matches domains
MAIL FROM from the envelope sender matches from
RCPT TO to the recipient matches to (each recipient is judged on its own)

A list that is not set gives no answer at its step. A whitelist with only to says nothing about the client or the sender: it accepts or refuses each recipient.

  • Accept only the machines that may send, by IP address or subnet: a local debug server, a relay inside a private network or a cluster.
  • Route by recipient: one flow per address or domain (see routing). A recipient refused by every flow is refused at RCPT TO.
  • Restrict the senders of a relay, for example to the domains of your SES identities.
  • A plain entry is compared with the whole value, ignoring case: support@example.com.
  • An entry starting with regexp: is a regular expression that must match the whole value: regexp:.*@example.com (smtp-relay adds the ^ and $ anchors). Regular expressions are case sensitive. An invalid regular expression stops the server at startup.
  • subnets entries are in CIDR notation, IPv4 or IPv6: 10.0.0.0/8, fd00::/8.
  • domains is compared with the client hostname found by reverse DNS lookup of its address. With options.disableReverseLookup: true there is no lookup, and the hostname is the address in brackets.

regexp:.* accepts anything: "ips": ["regexp:.*"] lets every client connect.

OptionTypeDescription
domainsstring[]

Allowed client hostnames, as resolved by reverse DNS lookup of the client address, checked on connection

On connection, the client is accepted if its address matches ips or subnets, or if its hostname matches domains

fromstring[]

Allowed senders: the envelope sender address (MAIL FROM) must match one entry

ipsstring[]

Allowed client IP addresses, checked on connection

On connection, the client is accepted if its address matches ips or subnets, or if its hostname matches domains

namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

subnetsstring[]

Allowed client subnets in CIDR notation (e.g. 10.0.0.0/8, fd00::/8), checked on connection

On connection, the client is accepted if its address matches ips or subnets, or if its hostname matches domains

tostring[]

Allowed recipients: every envelope recipient address (RCPT TO) must match one entry

typerequired"whitelist"

Type of the component

A debug server for Docker, accepting clients from the usual Docker bridge range and from the container itself:

configs/fake-smtp-docker.jsonc
// Can replace fakeSMTP.jar
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"localhost": {
"filters": [
// Allow only localhost
{
"type": "whitelist",
// Docker subnet are usually on class b network
"subnets": ["172.16.0.0/12", "127.0.0.1/32"]
}
],
"outputs": [
{
"type": "file",
// Send store files in emails/
"path": "./received_emails/"
}
]
}
},
// Listen on every interface so the server is reachable from outside its container
"bind": "0.0.0.0",
"options": {
"disableReverseLookup": false,
// Do not require auth
"authOptional": true
}
}

Clients from a private network, and only recipients of one domain:

whitelist.yaml
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
inbound:
filters:
- type: whitelist
subnets: ["10.0.0.0/8"]
to: ["regexp:.*@mydomain.com"]
outputs:
- type: file
path: ./received_emails/
bind: 0.0.0.0
options:
authOptional: true

With the default AND operator, a client outside 10.0.0.0/8 is refused at connection, and a recipient outside mydomain.com is refused at RCPT TO.