How to reject a sender domain in postfix

Though postfix is the most widely used MTA software on internet, it’s hard to find every detail for setup it correctly. For example, how to reject a sender domain in postfix? I took quite a few time to check the doc to get answers.

If the rejected domains list is short, it can go in main.cf:

smtpd_sender_restrictions = inline:{
  { example.com = reject }
  { other.example = reject} }

Otherwise some external file will do it as follows.

/etc/postfix/main.cf:

smtpd_sender_restrictions = hash:/etc/postfix/sender-access

/etc/postfix/sender-access:

example.com reject
other.example reject

Run “postmap /etc/postfix/sender-access” after editing the file.

If you have rspamd or spamassassin installed with postfix, it’s more easy to control rejected domains in them.

Comment