In many cases Postfix’s anvil module in not sufficient and we need something more intelligent and configurable. The popular issue is a limiting of incoming messages number from the specified domain. We will use a postfwd (Postfix Firewall Daemon). Let’s create a simple rule for this in /etc/postfix/postfwd.cf file.
id=RATE01 ; sender_domain == exampledomain.com ; action=rate(sender_domain/100/3600/450 4.7.1 Message delivery request rate limit exceeded)
This rule stops delivery of messages after exceeding the limit of 100 messages per hour. Restart the Postfw daemon.
Edit /etc/postfix/main.cf file and add the following line in a smtpd_recipient_restrictions option.
smtpd_recipient_restrictions = ... check_policy_service inet:127.0.0.1:10040, ...
Restart Postfix and test your configuration. For clients that exceed the limit you will see the following message in a log file.
NOQUEUE: reject: RCPT from mail.rootconsole.net[xxx.xxx.xxx.xxx]: 450 4.7.1 <test@rootconsole.net>: Recipient address rejected: Message delivery request rate limit exceeded;
Adjust the parameters to suit your needs.