A mail server that answers every client at full speed is a gift to abusers: they can try thousands of recipient guesses, test passwords or push spam through at a rate limited only by their own bandwidth. Tarpitting is the practice of deliberately slowing the conversation with suspicious clients so that abuse becomes expensive and slow, while well-behaved senders are barely affected. Rate shaping is the sibling technique of limiting how many connections, messages or recipients a client may use in a given time. Used together they form a quiet layer of defence that complements authentication, blocklists and content filtering. This guide explains what each technique does, how to apply it without breaking legitimate mail, how to configure it in Postfix and what to watch for. It pairs with brute-force defence, open relay checks and rate limits and backoff.
Terms and what they do
| Technique | How it works | Typical target |
|---|---|---|
| Error tarpit | Sleep for a few seconds after each client error, so repeated bad commands take longer | Address harvesting and probing |
| Soft error limit | After a number of errors, slow the client down; after a hard limit, disconnect it | Clients that keep failing |
| Greet pause | Wait before sending the banner; real servers wait, many spam tools do not | Bots that talk before the greeting |
| Connection rate limit | Cap new connections per client per time period | Floods, scans |
| Concurrency limit | Cap simultaneous connections per client | Aggressive parallel senders |
| Message rate limit | Cap messages per client per time period | Compromised accounts, bursts |
| Recipient limit | Cap recipients per message and per time period | Spam runs and harvesting |
| Greylisting | Temporarily refuse first contact from unknown triples. See greylisting | Fire-and-forget spam software |
What legitimate senders see
Legitimate software retries on temporary errors. A short delay or a 4xx reply (for example 421 or 450) causes a proper MTA to queue and retry, so the message arrives a little later. Applications that treat every error as final, or send from many parallel connections, are the ones that suffer. Before you tarpit, think about who connects to you:
- Your own applications and relays. They are known, authenticated and should have their own, more generous limits.
- Inbound mail from large providers. They retry politely and use a small number of IPs per domain; heavy tarpitting adds delay but rarely loses mail.
- Shared gateways and NAT. Many users can share one IP; per-IP limits can punish all of them for one bad client.
- Monitoring systems and scanners. Health checks that connect every few seconds may trip connection limits.
Postfix settings that matter
# /etc/postfix/main.cf (values are starting points, not recommendations for every site)
# Slow clients that make errors
smtpd_error_sleep_time = 1s
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 20
# Per-client limits tracked by the anvil service
smtpd_client_connection_count_limit = 20
smtpd_client_connection_rate_limit = 60
smtpd_client_message_rate_limit = 120
smtpd_client_recipient_rate_limit = 300
smtpd_client_event_limit_exceptions = $mynetworks
# Recipients per message
smtpd_recipient_limit = 100
# Make unknown clients wait before the greeting (postscreen)
postscreen_greet_wait = 6s
postscreen_greet_action = enforcePostfix tracks client behaviour with the anvil service, which counts connections, messages and recipients per client over a time window (set by anvil_rate_time_unit, 60 seconds by default). The smtpd_client_event_limit_exceptions parameter exempts trusted networks so your own applications do not trip the limits. When a limit is exceeded Postfix replies with a temporary error (421 or 450) and logs a warning; see reading mail logs for the log lines to look for. Other MTAs have equivalents, such as Exim's smtp_ratelimit options and ACL-based delays, and commercial gateways expose limits through their policy settings. Always check the documentation of your version.
Design principles
- Differentiate by trust. Authenticated users, known relays and your internal networks get high limits; anonymous connections get lower ones.
- Prefer temporary errors. A 4xx reply makes honest senders retry. Do not use 5xx for rate limits, or you will turn delay into bounces.
- Slow before you block. Delays frustrate bots at no cost to humans and well-behaved software.
- Count the right thing. A burst of 50 recipients in one message differs from 50 connections; set separate limits.
- Log every limit hit with the client, the limit and the time, so you can tell abuse from a misconfigured customer.
- Allow exceptions with an expiry. A temporary higher limit for a launch day is better than a permanent hole.
- Review regularly. Traffic patterns change; yesterday's limits may block next quarter's growth.
Tarpitting on outbound and API traffic
The same ideas protect a relay or API that customers use to send. A new account that suddenly submits thousands of messages, or a credential used from many places at once, deserves a slowdown before it deserves a ban. Typical controls are per-account message and recipient limits per hour and per day, ramp-up limits for new accounts, automatic throttling when bounce or complaint rates climb, and manual review for large changes. These controls protect your IP reputation and your other customers. See IP pools and tenant sending.
Common pitfalls
The most frequent mistake is setting one global limit and forgetting that a handful of trusted partners send in bursts: a payroll run, a newsletter or an invoice batch produces hundreds of messages in a minute, and a strict message-rate limit turns that into a pile of deferrals. Keep a short list of known bursty senders, give them their own limits and agree with them on the expected volume. A second pitfall is relying only on per-IP limits when attackers rotate through thousands of addresses; combine IP limits with per-account limits for authenticated traffic and with recipient-validation errors, which reveal harvesting regardless of the source address. A third is hiding the problem: if limits silently delay mail, no one notices until a customer complains, so alert on unusual numbers of limit hits and publish a contact address for partners who believe they are being throttled unfairly. Finally, test changes from outside. A simple script that opens connections at your chosen rate shows whether the server behaves as intended, and confirms that the log lines you plan to monitor actually appear.
Monitoring the effect
| Metric | What to look for |
|---|---|
| Limit hits per client | A few clients hitting limits repeatedly are likely abusive or misconfigured |
| Deferral rate on inbound | A sudden rise suggests limits are catching legitimate senders |
| Queue length at senders you know | Partners complaining of delays point to limits that are too tight |
| Rejected recipients per client | Many unknown-user errors indicate address harvesting |
| Authentication failures per IP | Credential-stuffing patterns. See brute force |
| Connection counts over time | Compare with a normal baseline to catch floods |
Rollout plan
- Collect a week of logs to learn normal connection, message and recipient rates per client.
- Set limits at several times the normal peak for the busiest legitimate clients and put those clients in the exception list.
- Enable the limits in log-only mode if your software supports it, or alert on the warning lines.
- Tighten gradually for anonymous traffic, checking partner feedback and deferral rates after each change.
- Document the limits and the process for requesting an exception.
- Revisit the numbers quarterly and after any major change in customers or volume.
Tarpitting is not a silver bullet and it does not replace authentication, content filtering or sender vetting. It is an inexpensive way to raise the cost of abuse and to buy time to react. Keep the limits generous for people you know, strict for people you do not and visible in your logs, and your servers will stay calm when someone else is not.
Check your server posture See whether your sending IP is listed anywhere.
References and further reading
Frequently asked questions
What is SMTP tarpitting?
Deliberately delaying responses to suspicious clients so that abuse such as address harvesting or password guessing becomes slow and costly.
Will tarpitting lose legitimate mail?
Rarely, because real MTAs retry on temporary errors, but strict limits can delay bulk senders or shared gateways.
Should rate limits return 4xx or 5xx?
Use temporary 4xx errors so honest senders retry; permanent errors turn delays into bounces.
How do I exempt my own applications?
List their networks in the client event limit exceptions or use authenticated, higher-limit paths.
How do I know the limits are working?
Track limit hits per client, deferral rates and partner complaints, and compare with baseline traffic.