Make Postfix reject emails if mail() "FROM:" header domain has not hosted or whitelisted on virtualmin server.


I am configuring virtualmin for my new server because old server was hacked and thus blacklisted due to mass email sending.

I am looking for a way like if any script is trying to send email them postfix can check if “FROM” header, if matched with hosted domain else, reject the email.

Example: Let’s say is hosted on my Virtualmin server

  1. Postfix should allow to send emails if mail() header has "From:" or "From:" or "From:"
  2. Postfix should reject emails if mail() header has "From:" or "From:" or any other domain which isn't hosted on my server.

Also, it there any way I can set mail sending limit per hour for any domain/server?

I have already configured SPF, DKIM and DMARC and logging the path of any files from emails would be sending so that I can track them:

mail.add_x_header = On
mail.log = /var/log/phpmail_files.log