Postfix domain whitelist

If you want to send e-mails just to a specific domain and block all other domains (e.g. when you are developing software and testing it without sending e-mails to your customers), you need to filter or rewrite the recipient. This domain whitelist can be done efficiently using postfix as filter.

Set up the relay in /etc/postfix/

relayhost = some.ip.or.hostname

Set up rewriting in /etc/postfix/

smtp_generic_maps = regexp:/etc/postfix/generic

Set the whitelist in /etc/postfix/generic


Note that you might have to regenerate /etc/postfix/generic.db and restart postfix.

postmap /etc/postfix/generic
sudo systemctl restart postfix

This is pretty simple and will ensure no accidential e-mails leave your development environment. You can test your setup using:

postmap -fq someone@allowed.domain regexp:/etc/postfix/generic
postmap -fq someoneelse@bad.domain regexp:/etc/postfix/generic
Copyright ©, 2002-2020.