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/main.cf
relayhost = some.ip.or.hostname
Set up rewriting in /etc/postfix/main.cf
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 firstname.lastname@example.org regexp:/etc/postfix/generic postmap -fq email@example.com regexp:/etc/postfix/generic