| Crates.io | srmilter |
| lib.rs | srmilter |
| version | 4.0.0 |
| created_at | 2026-01-22 14:39:45.228282+00 |
| updated_at | 2026-01-22 14:39:45.228282+00 |
| description | A Rust library for building mail filter (milter) daemons that integrate with Postfix |
| homepage | |
| repository | https://github.com/mpimg/srmilter |
| max_upload_size | |
| id | 2061805 |
| size | 145,894 |
A Rust library for building mail filter (milter) daemons that integrate with Postfix.
srmilter implements the milter protocol to receive emails from Postfix, parse them, and return classification decisions (accept, reject, or quarantine). It provides a simple API for writing custom email classifiers.
mail-parser crateCreate a new binary crate:
cargo init myfilter
cd myfilter
Add srmilter as a dependency:
cargo add srmilter
Edit src/main.rs to create your milter binary (see example below).
use srmilter::{ClassifyResult, Config, EmailClassifier, MailInfo, read_array, array_contains};
struct MyContext {
blocklist: Vec<String>,
}
fn main() -> impl std::process::Termination {
let ctx = MyContext {
blocklist: read_array("/etc/srmilter/blocklist.txt").unwrap_or_default(),
};
let classifier = EmailClassifier::builder(ctx).classify_fn(classify).build();
let config = Config::builder()
.email_classifier(classifier)
.enable_fork_mode()
.build();
srmilter::cli::cli(&config)
}
fn classify(ctx: &MyContext, mail_info: &MailInfo) -> ClassifyResult {
if array_contains(&ctx.blocklist, mail_info.get_from_address()) {
return mail_info.reject("sender on blocklist");
}
mail_info.accept("default")
}
The built-in CLI provides three subcommands:
# Run the milter daemon (default: 0.0.0.0:7044)
myfilter daemon [address] [--fork N] [--threads N] [--truncate N]
# Test classifier against an .eml file
myfilter test <file.eml> [sender] [recipients...]
# Dump parsed email headers and body
myfilter dump <file.eml> [-H] [-b] [--html]
--fork N: Fork up to N child processes (requires enable_fork_mode())--threads N: Use up to N threadsAdd to your Postfix main.cf:
smtpd_milters = inet:127.0.0.1:7044
Copyright © 2025 Donald Buczek buczek@molgen.mpg.de
Licensed under the European Union Public Licence (EUPL), Version 1.2. See the LICENSE file for details.