GoAdmio

postfwd

Rebuild the Postfwd rule file that limits how many emails the server, each domain, and each mail login can send

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/postfwd generates the rate-limiting rules that Postfwd (a Postfix policy service) uses to stop spam and runaway mail. It reads the limits stored in GoAdmio's databases and writes them as a fresh rule file. It can limit:

A message over a limit is rejected with a plain-language reason, such as Sorry, Daily limit exceeded: maximum 1000 messages allowed for domain example.com per day.

The command only writes the rule file. It does not restart or reload Postfwd, so the new rules apply after you restart the Postfwd service (see Examples). Postfwd itself must already be installed and used by Postfix.

Run the command as root: it writes to a system file without sudo.


Quick start

# Rebuild the Postfwd rules
/go/postfwd

Syntax

/go/postfwd

The command takes no arguments. Anything you add is written to the command log but otherwise ignored.

Every run is recorded in /var/log/go/postfwd.log, with the time and the arguments you passed.


Options

None. The limits come from GoAdmio's databases:

Setting Where it is stored Meaning
ServerLimit config.db, Config table, row 1 Messages per day for the whole server.
ExternalLimit config.db, Config table, row 1 Messages per day from external (non-local) connections. 0 turns the rule off.
DomainLimit config.db, Config table, row 1 Messages per day for each sending domain. 0 turns the rule off.
UserLimit config.db, Config table, row 1 Messages per hour for each mail login. 0 turns the rule off.
PostfwdIgnore site.db, Site table 1 exempts the account's domain and logins from the global domain and login limits.
PostfwdDomainLimit site.db, Site table Custom messages per day for an exempt domain. 0 means no custom limit.
PostfwdUserLimit site.db, Site table Custom messages per hour for each login of an exempt domain. 0 means no custom limit.

Output

The command prints nothing. Check the rule file to see the result.

Operating system Rule file
AlmaLinux, Rocky, CentOS, Red Hat, Fedora /etc/postfwd/postfwd.cf
Debian, Ubuntu /etc/postfwd.cf

The file is overwritten on every run, so edits you make to it by hand are lost.

Example rule file

With a server limit of 5000, an external limit of 500, a domain limit of 1000, a login limit of 100, and one exempt domain with its own limits, the file looks like this:

id=Server; client_address!=8.8.8.8; action=rate(sender/5000/86400/REJECT Sorry, Daily limit exceeded: maximum 5000 messages allowed for server per day)
id=External; client_address!=127.0.0.1; action=rate(sender/500/86400/REJECT Sorry, Daily limit exceeded: maximum 500 messages allowed for external IPs per day)
id=Domain1; sender_domain==shop.example.com; action=rate(sender/2000/86400/REJECT Sorry, Daily limit exceeded: maximum 2000 messages allowed for domain $$sender_domain per day)
id=SASL1; sasl_username=~/@shop\.example\.com$/; action=rate(sender/200/3600/REJECT Sorry, exceeded 200 messages in 60 minutes for $$sasl_username)
id=ExcludeDomain1; sender_domain==shop.example.com; action=ok
id=ExcludeSASL1; sasl_username=~/@shop\.example\.com$/; action=ok
id=Domain; sender_domain=~/.*/; action=rate(sender/1000/86400/REJECT Sorry, Daily limit exceeded: maximum 1000 messages allowed for domain $$sender_domain per day)
id=SASL; sasl_username=~/.*/; action=rate(sender/100/3600/REJECT Sorry, exceeded 100 messages in 60 minutes for $$sasl_username)

Log

Each run appends one line to /var/log/go/postfwd.log:

[Nov 21 12:00:00]# postfwd

Examples

# Rebuild the rules
/go/postfwd
# Look at the generated rules (RHEL family)
cat /etc/postfwd/postfwd.cf
# Look at the generated rules (Debian and Ubuntu)
cat /etc/postfwd.cf
# Apply the new rules (the service name can differ by system)
systemctl restart postfwd

Troubleshooting

Symptom Likely cause Fix
New limits don't apply The command doesn't restart Postfwd. Restart the Postfwd service.
ambiguous redirect The operating system isn't supported, so no rule file path was chosen. Not supported on this system.
Permission denied when writing the file The command wasn't run as root. Run it as root.
All outgoing mail is rejected, or the rules are invalid ServerLimit is empty or 0. The server rule is always written. Set ServerLimit to a number above 0, then run the command again.
A domain isn't limited by the global domain or login limit Its PostfwdIgnore is 1, which exempts it. Set a custom limit for it, or turn PostfwdIgnore off.
An exempt domain has no limits at all Its custom limits are 0. It is still subject to the server and external rules. Set PostfwdDomainLimit or PostfwdUserLimit.
integer expression expected A limit value in the database is empty or not a number. Correct the value, then run the command again.
Your hand edits to the rule file disappeared The file is rewritten on every run. Make permanent changes in the databases, not in the file.

Details

Rules and their order

Postfwd checks rules from the top of the file down. A message that goes over a limit is rejected. Otherwise Postfwd moves on to the next rule, and an ok rule accepts the message right away. The command writes the rules in this order.

Order Rule Written when Applies to Limit
1 Server Always Every connection ServerLimit per day
2 External ExternalLimit isn't 0 Connections that don't come from 127.0.0.1 ExternalLimit per day
3 Domain<n> The account has PostfwdIgnore=1 and PostfwdDomainLimit of 1 or more That domain PostfwdDomainLimit per day
4 SASL<n> The account has PostfwdIgnore=1 and PostfwdUserLimit of 1 or more Logins ending in @<domain> PostfwdUserLimit per hour
5 ExcludeDomain<n> and ExcludeSASL<n> The account has PostfwdIgnore=1 That domain and its logins Accepts the message, so the global rules below are skipped
6 Domain DomainLimit isn't 0 Every domain DomainLimit per day
7 SASL UserLimit isn't 0 Every mail login UserLimit per hour

Because the exemption rules (5) come before the global rules (6 and 7), an exempt domain skips the global domain and login limits. The server and external rules (1 and 2) still apply to everyone.

[!NOTE] All rules count with Postfwd's sender counter, so a limit is counted separately for each sender address, not as one total for the whole server, domain, or login. Test your limits to be sure they behave the way you expect.

Where the settings are changed

The PostfwdIgnore, PostfwdDomainLimit, and PostfwdUserLimit values belong to each account. The four global limits belong to the server's configuration. After you change any of them, run this command again and restart Postfwd.

flowchart TD
    A["postfwd"] --> B["Log the run, read the four global limits"]
    B --> C{"Operating system"}
    C -- "RHEL family" --> D["Rule file: /etc/postfwd/postfwd.cf"]
    C -- "Debian / Ubuntu" --> E["Rule file: /etc/postfwd.cf"]
    D --> F["Write the Server rule, overwriting the file"]
    E --> F
    F --> G["Add the External rule if its limit isn't 0"]
    G --> H["Add custom limit rules for accounts with PostfwdIgnore=1"]
    H --> I["Add exemption rules for those accounts"]
    I --> J["Add the global Domain and SASL rules if their limits aren't 0"]

See also

Command Description
installmail Install and configure webmail services (Postfix and Dovecot)
mynetworks Set Postfix trusted networks and restart the mail server
outgoing List today's outgoing messages from the mail log, with time, sender, recipient, IP, and subject
mailtop Check the most active email accounts in GoAdmio
spam Track spam email accounts in GoAdmio
deletemailqueue Permanently delete every email waiting in the Postfix mail queue