How to rate limit outgoing SMTP connections for Postfix
I have a postfix instance running on a VM. The VM provider shuts us down if we exceed a threshold of SMTP connections per minute - something like 10. In a typical day we might send 1000 messages, so 10 is fine. However it is a mailman server so the peak rate often exceeds 10. The port 25 is then blocked for a while. This creates a backlog. Retries on the backlog create "bursts" of connections far higher than 10. The end result is once we are blocked, we remain blocked until someone manually intervenes.
The "obvious" fix seems to be to ensure postfix stays within the limit - ie outbound connection throttling. Or at the very least limit the number of smtp delivery processes running to 1.
Is there a way do to this?
Solution 1:
Look at "policyd" for Postfix. That should be able to fix your ratelimiting. That said, 10 SMTP connections per minute seems stupidly low, and I'd challenge the provider on that (600 per hour may be reasonable)
Solution 2:
Are you using a smart relay?
There's a parameter for main.cf, called
default_destination_concurrency_limit = 10
If you are using a smart relay, that just might do the job.
The other option is to set this in the master.cf:
smtp unix - - n - 10 smtp
Since every smtp process delivers one email, this limits the number of outbound connections to a maximum of 10.