{"id":661,"date":"2016-07-05T07:59:06","date_gmt":"2016-07-05T02:29:06","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=661"},"modified":"2026-08-30T18:32:43","modified_gmt":"2026-08-30T13:02:43","slug":"configure-thrttling-for-outgoing-mails-in-postfix","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/configure-thrttling-for-outgoing-mails-in-postfix\/","title":{"rendered":"How to Rate Limit Emails to Gmail Using Postfix"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most renowned Email Service Providers (ESPs), such as Gmail, Hotmail, and Yahoo, do not prefer receiving multiple emails from the same server in a short period. If they detect that a server&#8217;s IP address is sending bursts of emails within a short period or over a single connection, they may temporarily block or restrict the IP address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can help prevent this by implementing rate limiting on the server side so that the server IP addresses remain clean and are less likely to be blocked. Postfix can be configured to rate-limit emails based on their recipient domains.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Root or sudo access to the mail server.<\/li>\n\n\n\n<li>Postfix installed and configured.<\/li>\n\n\n\n<li>Postfix version 2.5 or later.<\/li>\n\n\n\n<li>Basic knowledge of Postfix configuration.<\/li>\n\n\n\n<li>Access to the Postfix log file for testing and troubleshooting.<\/li>\n\n\n\n<li>A backup of the existing Postfix configuration.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n<p>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&#8217;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.<\/p>\n<p>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.<\/p>\n<p>We will use custom transports in postfix configuration to achieve this rate limiting. Custom transports are supported in postfix &gt; v2.5. Check your postfix version using the following command:<\/p>\n<p>[root@~]# postconf mail_version<br \/>mail_version = 2.8.5<\/p>\n<p>If postfix is older than 2.5, upgrade it.<\/p>\n<p>Now, define required additional transport in postfix master.cf file:<\/p>\n<p>smtp-gmail unix &#8211;\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0 n\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0 smtp<br \/>-o syslog_name=smtp-gmail<\/p>\n<p>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.<\/p>\n<p>Define the required throttling (rate limits) settings in postfix main.cf<\/p>\n<p>smtp-gmail_destination_rate_delay = 12s<br \/>smtp-gmail_destination_concurrency_limit = 1<br \/>smtp-gmail_destination_recipient_limit = 2<br \/>smtp-gmail_initial_destination_concurrency=1<\/p>\n<p>The syntax is as follows: trasntport-name_variable-name=value<\/p>\n<p>Here the transport name I am using is smtp-gmail. You can use anything of you own choice.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>initial_destination_concurrency: This decides the initial number of parallel deliveries. Default is 5, you don&#8217;t want that probably, so set it as 1.<\/p>\n<p>You can get more information about the parameters here: http:\/\/www.postfix.org\/postconf.5.html<\/p>\n<p>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<\/p>\n<p>\/\\@gmail\\.com$\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 smtp-gmail:<\/p>\n<p>The format of the above file is regexp. Lookups to regexp tables are fast so probably you should use those. For regexp to work you should have regexp support built into postfix. Find out using this command<\/p>\n<p>postconf -m<\/p>\n<p>You should get the following result, showing all supported lookup tables<\/p>\n<p># postconf -m<br \/>btree<br \/>cidr<br \/>environ<br \/>hash<br \/>internal<br \/>ldap<br \/>nis<br \/>pcre<br \/>proxy<br \/>regexp<br \/>static<br \/>tcp<br \/>texthash<br \/>unix<\/p>\n<p>Once the transport file is created, make sure to create the corresponding db, which will be actually used by postfix. Use postmap command.<\/p>\n<p>postmap\u00a0 \/etc\/postfix\/transport<\/p>\n<p>Make postfix use this transport table. Edit main.cf and add the following:<\/p>\n<p>transport_maps = regexp:\/etc\/postfix\/transport<\/p>\n<p>Make sure you use regexp prefix.<\/p>\n<p>Reload postfix.<\/p>\n<p>Test the configuration.<\/p>\n<p>Create a file containing two or more different gmail addresses. Then you can use a loop to send mails to them using the command line.<\/p>\n<p>for i in `cat recpts`; do echo &#8220;hello&#8221; | mail -s &#8220;testing throttling&#8221; $i; done<\/p>\n<p>recpts is the file containing recipients&#8217; addresses.<\/p>\n<p>Tail the maillog and grep for the transport name. You should get the following messages:<\/p>\n<p>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\u00a0aasdafdsf.49)<br \/>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\u00a0asdadassad.73)<br \/>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)<\/p>\n<p>You can see that the transport &#8216;smtp-gmail&#8217; is being called every five minutes ( as set in postfix main.cf).<\/p>\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By configuring a custom transport in Postfix, you can control the rate at which emails are delivered to a specific recipient domain. This helps prevent sudden bursts of outgoing emails and can reduce the likelihood of triggering receiving-server rate limits or temporary delivery restrictions. After configuring the transport, always monitor the Postfix mail logs to confirm that the rate limiting is working as expected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Most renowned Email Service Providers (ESPs), such as Gmail, Hotmail, and Yahoo, do not prefer receiving multiple emails from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[],"class_list":["post-661","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-aF","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":11178,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions\/11178"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}