How to Configure Recipient-Based Rate Limiting in Postfix
Introduction
Email service providers (ESPs) such as Gmail, Yahoo, and Outlook monitor the rate at which emails are received from a sender. Sending a large number of emails over a short period or through a single connection may trigger rate limits or cause the sending IP address to be temporarily blocked. Postfix provides recipient-based throttling using custom transports, allowing administrators to control the delivery rate for specific recipient domains. This guide explains how to configure Postfix to rate-limit outbound emails based on recipient domains, helping improve email deliverability and maintain a good sender reputation.
Prerequisites
Before configuring recipient-based rate limiting in Postfix, ensure the following requirements are met:
- A Linux server with Postfix version 2.5 or later installed.
- Root or sudo privileges.
- Basic knowledge of Postfix configuration files (
main.cfandmaster.cf). - Regexp support enabled in Postfix (
postconf -mshould listregexp). - Access to reload or restart the Postfix service.
- A valid mail server configuration with outbound email delivery working correctly.
IMPLEMENTATION
Yahoo be Most of the renowned ESPs such as Gmail or Hotmail or yahoo do not like to mailed to from the same address multiple times in a short span. If they detect (and they will) that a server’s IP is sending out bursts of emails in short span of time or over a single connection, they will most certainly block your IP.sending
Here is how we can negate this block by rate limiting on the server side so that the server IP(s) remain clean and unblocked. We can configure postfix to rate limit the mails based on their recipient domains. Suppose we need to rate limit mails to gmail to 1000 per hour, this can be achieved using the following steps.
We will use custom transports in postfix configuration to achieve this rate limiting. Custom transports are supported in postfix > v2.5. Check your postfix version using the following command:
[root@~]# postconf mail_version
mail_version = 2.8.5
If postfix is older than 2.5, upgrade it.
Now, define required additional transport in postfix master.cf file:
smtp-gmail unix – – n – 1 smtp
-o syslog_name=smtp-gmail
syslog_name will specify the name by which messages related with this transport will be logged in maillog. This will help us to identify if the custom transport is working or not.
Define the required throttling (rate limits) settings in postfix main.cf
smtp-gmail_destination_rate_delay = 12s
smtp-gmail_destination_concurrency_limit = 1
smtp-gmail_destination_recipient_limit = 2
smtp-gmail_initial_destination_concurrency=1
The syntax is as follows: trasntport-name_variable-name=value
Here, the transport name I am using is smtp-gmail. You can use anything of you own choice.
destination_rate_delay: This defines the delay between individual deliveries to the destination using this transport. Set this as per required. Suppose you want 10 deliveries per minute to gmail, then you can set it up like 60/10 = 6s.
destination_concurrency_limit: This decides the number of parallel deliveries to the destination using this transport. Setting it one means only one mail will be delivered once.
destination_recipient_limit: This decides the number of recipients per mail delivery. Setting this parameter to a value of 1 changes the meaning of the corresponding per-destination concurrency limit from concurrency per domain into concurrency per recipient. So set this to 2. This will take care of the domain. If you set it to 1, throttling will work only if you send mails to the same recipient and not for the same recipient domain.
initial_destination_concurrency: This decides the initial number of parallel deliveries. Default is 5, you don’t want that probably, so set it to 1.
You can get more information about the parameters here: http://www.postfix.org/postconf.5.html
Create a transport map file, so that mails to gmail.com are directed to our new transport (smtp-gmail). Add the following to /etc/postfix/transport
/\@gmail\.com$/ smtp-gmail:
The format of the above file is regexp. Lookups to regexp tables are fast, so you probably should use those. For regexps to work, you should have regex support built into postfix. Find out using this command
postconf -m:
You should get the following result, showing all supported lookup tables
# postconf -m
btree
cidr
environ
hash
internal
ldap
nis
pcre
proxy
regexp
static
tcp
texthash
unix
Once the transport file is created, make sure to create the corresponding db, which will actually be used by postfix. Use the postmap command.
postmap /etc/postfix/transport
Make postfix use this transport table. Edit main.cf and add the following:
transport_maps = regexp:/etc/postfix/transport
Make sure you use the regexp prefix.
Reload Postfix.
Test the configuration.
Create a file containing two or more different Gmail addresses. Then you can use a loop to send emails to them using the command line.
for i in `cat recpts`; do echo “hello” | mail -s “testing throttling” $i; done
recpts is the file containing recipients’ addresses.
Tail the maillog and grep for the transport name. You should get the following messages:
Oct 5 10:33:26 smtp-gmail/smtp[31905]: A8AB21EE201: to=, relay=gmail-smtp-in.l.google.com[xxx.xx.xx.xx]:25, delay=1466, delays=0.09/1465/0.25/0.84, dsn=2.0.0, status=sent (250 2.0.0 OK xxxxxx aasdafdsf.49)
Oct 5 10:38:28 smtp-gmail/smtp[31945]: AFF7B1EE206: to=, relay=gmail-smtp-in.l.google.com[xxx.xx.xx.xx.]:25, delay=1768, delays=0.09/1766/0.24/1.2, dsn=2.0.0, status=sent (250 2.0.0 OK xxxxxx asdadassad.73)
Oct 5 10:43:29 smtp-gmail/smtp[31985]: B18DC1EE208: to=, relay=gmail-smtp-in.l.google.com[xxx.xx.xx.xx.]:25, delay=2069, delays=0.09/2068/0.25/0.75, dsn=2.0.0, status=sent (250 2.0.0 OK 1317825809 fn12si1423894wbb.51)
You can see that the transport ‘smtp-gmail’ is being called every five minutes ( as set in postfix main.cf).
Conclusion
Configuring recipient-based throttling in Postfix is an effective way to control the rate of outbound email delivery to specific domains such as Gmail, Yahoo, or Outlook. By using custom transports and transport maps, administrators can define delivery delays, limit concurrent connections, and control the number of recipients per delivery. This helps prevent IP reputation issues, reduces the risk of provider-imposed rate limits, and improves overall email deliverability. After completing the configuration, verify the settings by monitoring the mail logs and confirming that emails are routed through the configured transport at the expected rate.
