Skip to main content

postfixlimit

A lightweight, modern rate-limiting policy service for Postfix that protects you from outbound spam and runaway application mail.

Features

  • Limits the number of messages sent through the Postfix MTA
  • Supports multiple key types: client IP address, SASL authentication username, or sender address
  • Flexible rate limit configuration with a global default — e.g. "100 messages per 2 hours"
  • Pluggable storage backends: in-memory or Redis
  • Three rate-limiting strategies: fixed-window, moving-window, and sliding-window

Installation

Quick Start

# install from pypi
PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install postfixlimit
# or installl from git repo directly
PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install git+https://github.com/yaroslaff/postfixlimit


wget https://raw.githubusercontent.com/yaroslaff/postfixlimit/refs/heads/master/contrib/postfixlimit.service
wget https://raw.githubusercontent.com/yaroslaff/postfixlimit/refs/heads/master/contrib/postfixlimit.conf

cp postfixlimit.service /etc/systemd/system/
systemctl daemon-reload

cp postfixlimit.conf /etc/

Once installed, edit /etc/postfixlimit.conf to configure field, default_limit, and any per-sender limits. Then start the daemon:

systemctl start postfixlimit

To cleanly uninstall:

PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx uninstall postfixlimit

Systemd Unit File

Copy contrib/postfixlimit.service to /etc/systemd/system/postfixlimit.service, then reload and start the service:

systemctl daemon-reload
systemctl start postfixlimit

Configuration

An example configuration file is provided at contrib/postfixlimit.conf. Save it as /etc/postfixlimit.conf:

# Main server options
[server]
address = 127.0.0.1
port = 4455

# field is one of: sender / sasl_username / client_address
field = sender
default_limit = 5/day
action = DEFER
action_text = Limit ({limit}) exceeded for {field}={key}

# Storage backend: memory:// (default) or Redis
# storage = redis://localhost:6379/
storage = memory://

# Rate-limiting strategy: fixed-window / sliding-window / moving-window
strategy = fixed-window

dump_period = 60
dump_file = /var/lib/postfixlimit/limits.txt
log_file = /var/log/postfixlimit/postfixlimit.log

# Per-sender overrides
[limits]
aaa@example.com = 100 / day

Rate Limit Syntax

postfixlimit uses the limits library. Limits follow its string notation:

[count] [per|/] [n (optional)] [second|minute|hour|day|month|year]

Postfix Integration

Add the following to smtpd_recipient_restrictions in your Postfix main.cf:

smtpd_recipient_restrictions =
    check_policy_service inet:127.0.0.1:4455

Viewing Counter State

Every dump_period seconds, postfixlimit writes the current counter values to dump_file:

root@micromail:~# cat /var/lib/postfixlimit/limits.txt
Limits (2026-04-08 22:00:04):
  stg: 200 per 1 day remaining: 200
  odoomarketing: 1000 per 1 day remaining: 1000
  odoocare: 7000 per 1 day remaining: 6095
  mainweb: 3000 per 1 day remaining: 2991

Resetting Counters

Redis storage — reset a specific counter:

postfixlimit --reset COUNTERNAME

Reset all counters:

postfixlimit --reset ALL

In-memory storage — simply restart the daemon; all counters are cleared on startup.

Developer Reference

Postfix policy protocol specification: https://www.postfix.org/SMTPD_POLICY_README.html

Metadata

Release files for postfixlimit 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postfixlimit 0.0.4
File Size Uploaded Provenance
postfixlimit-0.0.4.tar.gz 10.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for postfixlimit 0.0.4
File Interpreter ABI Platform
postfixlimit-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / postfixlimit-0.0.4.tar.gz

Download URL postfixlimit-0.0.4.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
529d41cc44a4b87643a0d8bd1d56ba3395f00dbb056d5318d1102ccb3f87cad8
BLAKE2b-256 checksum
How to use checksums
5b4c192cce2b729121d7019b298d87d4a331d51c8680617dd19bd0f5cafe246e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.13.5 HTTPX/0.28.1

Release files / postfixlimit-0.0.4-py3-none-any.whl

Download URL postfixlimit-0.0.4-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4b48782079ee9a4dbc724bd782f0279a1e58b8209ede45cfaa32362cd7eecf1
BLAKE2b-256 checksum
How to use checksums
2a3b8b1842689a402372803351474a1c61a0875bc2a9afb8a23a12d7b63d086c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.13.5 HTTPX/0.28.1

Security for postfixlimit 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page