Skip to main content

Simple postfix policy service (check_policy_service) for per-user limit number of sent messages (by IP, SASL username or sender address)

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postfixlimit-0.0.4.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postfixlimit-0.0.4-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file postfixlimit-0.0.4.tar.gz.

File metadata

  • Download URL: postfixlimit-0.0.4.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.5 HTTPX/0.28.1

File hashes

Hashes for postfixlimit-0.0.4.tar.gz
Algorithm Hash digest
SHA256 529d41cc44a4b87643a0d8bd1d56ba3395f00dbb056d5318d1102ccb3f87cad8
MD5 8df6d13cb1588bfb8d7f12d172d621c2
BLAKE2b-256 5b4c192cce2b729121d7019b298d87d4a331d51c8680617dd19bd0f5cafe246e

See more details on using hashes here.

File details

Details for the file postfixlimit-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: postfixlimit-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.5 HTTPX/0.28.1

File hashes

Hashes for postfixlimit-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f4b48782079ee9a4dbc724bd782f0279a1e58b8209ede45cfaa32362cd7eecf1
MD5 8711092466cef748ef2d7bbd7f85a632
BLAKE2b-256 2a3b8b1842689a402372803351474a1c61a0875bc2a9afb8a23a12d7b63d086c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page