Postfix milter Integration¶
This guide covers integrating tobira with Postfix using the Python milter daemon.
Prerequisites¶
- Postfix mail server
- Python 3.9+
libmilter-devsystem package- tobira API server running and accessible
Installation¶
-
Install tobira with milter support:
-
Create the configuration file
/etc/tobira/milter.conf: -
Create the socket directory:
-
Install the systemd service:
-
Configure Postfix to use the milter. Add to
/etc/postfix/main.cf: -
Reload Postfix:
Configuration Options¶
| Option | Default | Description |
|---|---|---|
api_url |
http://127.0.0.1:8000/predict |
tobira API endpoint URL |
socket |
unix:/var/run/tobira/milter.sock |
Milter socket path (UNIX or TCP) |
timeout |
10 |
API connection timeout in seconds |
fail_action |
accept |
Action on API failure: accept or tempfail |
reject_threshold |
0.9 |
Score threshold for rejection (0 to disable) |
add_headers |
true |
Add X-Tobira-Score and X-Tobira-Label headers |
Socket Types¶
The milter supports both UNIX and TCP sockets:
# UNIX socket (recommended for same-host deployment)
socket = unix:/var/run/tobira/milter.sock
# TCP socket (for remote deployment)
socket = inet:8899@127.0.0.1
Headers Added¶
When add_headers = true, the milter adds these headers to each email:
| Header | Example | Description |
|---|---|---|
X-Tobira-Score |
0.95 |
ML spam probability |
X-Tobira-Label |
spam |
Classification label |
Fail Handling¶
fail_action |
Behavior |
|---|---|
accept |
Accept the email without ML scoring (fail-open) |
tempfail |
Return a temporary failure, asking the sender to retry |
Systemd Service¶
The included systemd service file runs the milter with security hardening:
- Runs as dedicated
tobirauser ProtectSystem=strict— Read-only filesystemProtectHome=true— No access to home directoriesNoNewPrivileges=true— Cannot gain additional privilegesPrivateTmp=true— Isolated temporary directory
Verification¶
Check the milter is running:
Check the socket exists:
Send a test email and verify headers:
Troubleshooting¶
Socket permission denied: Ensure the tobira user has write access to the socket directory and Postfix can read the socket.
pymilter installation fails: Install libmilter-dev before installing the Python package.
Emails being rejected: Check reject_threshold setting. Set to 0 to disable rejection and only add headers.