Postfix rate limiter SMTP policy daemon
It depends on the Postfix policy delegation protocol, it searches for the sasl_username
and based on the defined limits stored in a MySQl database it rejects or allows action=DUNNO
the email to be sent.
```txt
USAGE:
policyd-rate-limit [OPTIONS] --dsn
FLAGS: -h, --help Prints help information -V, --version Prints version information
OPTIONS:
-d, --dsn
SUBCOMMANDS: cuser Create the user if not found, defaults: 100 messages per day help Prints this message or the help of the given subcommand(s) ```
For the subcommand cuser
:
```txt Create the user if not found, defaults: 100 messages per day
USAGE:
policyd-rate-limit --dsn
FLAGS: -h, --help Prints help information -V, --version Prints version information
OPTIONS:
-l, --limit
Use a supervisor (immortal) to run policyd-rate-limit
,
for example to create users if not found and to only allow 3 emails every hour
use:
policyd-rate-limit -d mysql://root:test@tcp(localhost)/policyd -s /var/run/policy-rate-limit.sock cuser -l 3 -r 3600
The database schema:
``sql
CREATE SCHEMA IF NOT EXISTS
policyd` DEFAULT CHARACTER SET utf8 COLLATE utf8generalci;
USE policyd;
CREATE TABLE IF NOT EXISTS ratelimit
(
username
VARCHAR(128) NOT NULL COMMENT 'sender address (SASL username)',
quota
INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'limit',
used
INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'current recipient counter',
rate
INT(10) UNSIGNED DEFAULT '0' COMMENT 'seconds after which the counter gets reset',
rdate
DATETIME NOT NULL DEFAULT CURRENTTIMESTAMP COMMENT 'datetime when counter was reset',
PRIMARY KEY (username
))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8general_ci;
```
Add the path of the policy-rate-limit socket to smtpd_sender_restrictions
for example:
smtpd_sender_restrictions: check_policy_service { unix:/tmp/policy-rate-limit.sock, default_action=DUNNO }
check the perms of the socket, you may need
chmod 666