I’ll try to explain myself better, let’s say that my NS is hacked and the attacker uses it to shoot spam emails all over the internet. To limit the damage I would like to set a limit on hourly sending regardless of the IP from which it comes.
In the meantime, I thank you.
fail2ban is very useful in case of attack attempts due to the blocking it applies, but it cannot do anything in case of theft of valid credentials.
For this reason I would like to limit the maximum number of messages that can be sent, for example, per hour
Best would be to monitor the Mail-Queue.
Limiting without real reason can also limit legit info mailing to clients (example).
Wheras, when a spammer strikes, the mail queue is always filled up. If it’s full, and you are not aware of a reason, it’s spam and can be emptied (mailqueue) and repaired / excluded whatever. Often this comes from compromised or to easy access credentials.
Zabbix, on NS8, would be a nice option for this…
Postfix also has limiting options…
See here for some ideas:
I gave it a try it seems not so hard to add a rate limit, maybe a bit basic
but add this setting and you will send one email per 30 seconds, if you want 200 emails per hour, set it to 18s
smtp_destination_rate_delay = 30s
smtp_destination_rate_delay: Postfix doc says “The default amount of delay that is inserted between individual deliveries over the same message delivery transport, regardless of destination”. In the setting above, I added a “wait time” of 30s second before the next e-mail should be delivered. The default is “0s” which means no delay between sending mails.
This setting slows down the sending a lot
smtp_destination_concurrency_limit: As per the Postfix documentation: “The maximal number of parallel deliveries to the same destination via the smtp message delivery transport.” Example: If your mail server sends mails to several gmail.com recipients, Postfix will only deliver two mails at the same time. The default is 20. This could also be set with default_destination_concurrency_limit.
This setting is particularly helpful in case a spammer bombards a certain domain. Often the recipient mail server then refuses the sent mails (your real mails as well) with a 421, 450 or 451 SMTP response that you’re sending too many mails too quickly.
This could be interesting too for reducing the number of recipient of an email for example if you send an email with 20 recipients, it should send several email and be limited by the rate limit
smtp_destination_recipient_limit (default: $default_destination_recipient_limit)
The maximal number of recipients per message for the smtp message delivery transport. This limit is enforced by the queue manager. The message delivery transport name is the first field in the entry in the master.cf file.
Setting this parameter to a value of 1 changes the meaning of smtp_destination_concurrency_limit from concurrency per domain into concurrency per recipient.