Skip to content

Rspamd

Rspamd checks message content and authentication signals. This recipe connects the Debian package to Postfix through Milter: port 11332 for Postfix, 11333 for CLI scans and 11334 for the controller. All three listen on loopback.

Setup

First prepare your values and Postfix. Run this single block as root. It preserves existing Milters. If Rspamd fails, Postfix returns a temporary error instead of delivering unscanned mail. Redis stores learning and statistics data in this standard mailserver setup.

set -euo pipefail
. /root/mailserver.env
apt-get install -y --no-install-recommends rspamd redis-server
install -d /etc/rspamd/local.d
cat > /etc/rspamd/local.d/worker-normal.inc <<'EOF'
bind_socket = "127.0.0.1:11333";
EOF
cat > /etc/rspamd/local.d/worker-proxy.inc <<'EOF'
bind_socket = "127.0.0.1:11332";
milter = yes;
timeout = 120s;
upstream "local" {
  default = yes;
  self_scan = yes;
}
EOF
cat > /etc/rspamd/local.d/worker-controller.inc <<'EOF'
bind_socket = "127.0.0.1:11334";
EOF
cat > /etc/rspamd/local.d/redis.conf <<'EOF'
servers = "127.0.0.1";
EOF
rspamadm configtest
systemctl enable --now redis-server rspamd
systemctl restart rspamd
postconf -e 'milter_protocol=6' 'milter_default_action=tempfail'
python3 - <<'PY'
import subprocess
endpoint = "inet:127.0.0.1:11332"
for name in ("smtpd_milters", "non_smtpd_milters"):
    current = subprocess.check_output(["postconf", "-h", name], text=True).strip()
    parts = [p.strip() for p in current.split(",") if p.strip()]
    if endpoint not in parts:
        parts.append(endpoint)
    subprocess.run(["postconf", "-e", name + "=" + ", ".join(parts)], check=True)
PY
postfix check
systemctl reload postfix
systemctl is-active redis-server rspamd postfix

The controller is not publicly accessible. Add access controls and TLS separately if you need remote access. The official Postfix integration guide describes the Milter interface.

Test

This block checks configuration, listeners, a real GTUBE scan and enforcement through SMTP/Postfix. It sends only to localhost. GTUBE is a deliberately detectable synthetic spam test string.

set -euo pipefail
. /root/mailserver.env
rspamadm configtest
for attempt in {1..60}; do
  if ss -ltn | grep -q '127.0.0.1:11333'; then break; fi
  sleep 1
done
ss -ltn | grep -E '127\.0\.0\.1:1133[234]'
test "$(postconf -h milter_default_action)" = tempfail
postconf -h smtpd_milters | grep -F 'inet:127.0.0.1:11332'
install -d -m 0700 /root/mail-tests
python3 - <<'PY'
from email.message import EmailMessage
from email.policy import SMTP
from pathlib import Path
import os
message = EmailMessage()
message["From"] = "probe@" + os.environ["DOMAIN"]
message["To"] = "postmaster@" + os.environ["DOMAIN"]
message["Subject"] = "Local Rspamd functional test"
message.set_content("XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X")
Path("/root/mail-tests/gtube.eml").write_bytes(message.as_bytes(policy=SMTP))
PY
rspamc -h 127.0.0.1:11333 --json /root/mail-tests/gtube.eml > /root/mail-tests/gtube.json
jq -e '.symbols.GTUBE != null and .action == "reject"' /root/mail-tests/gtube.json
python3 - <<'PY'
from pathlib import Path
import os, smtplib
with smtplib.SMTP("127.0.0.1", 25, timeout=30) as smtp:
    try:
        smtp.sendmail("probe@" + os.environ["DOMAIN"], ["postmaster@" + os.environ["DOMAIN"]],
                      Path("/root/mail-tests/gtube.eml").read_bytes())
    except smtplib.SMTPDataError as error:
        assert error.smtp_code >= 500, error
        print("PASS: Postfix milter rejects the local GTUBE test message after DATA.")
    else:
        raise SystemExit("ERROR: Postfix accepted GTUBE; check the milter integration.")
PY

Expected: valid configuration, GTUBE in the JSON and action reject; Postfix rejects the same message after DATA with a permanent error. A CLI scan alone does not prove the Milter connection. This test does not calibrate spam probability. Some synthetic subjects and diagnostic messages in the shared command blocks are in German.