Examples

Files in this directory:

suggested-minimum-filter-for-windows-clients

If you are protecting MS Windows clients, this is the minimum suggested filter. You might want to use a stronger filter.

stream-by-domain-filter

An example showing how to use the stream_by_domain function.

example-filter-with-async-checks

An example filter using Mail::MIMEDefang::Async to run DNS blacklist, sender-domain, virus, and spam checks in parallel rather than sequentially.

Requires: AnyEvent, AnyEvent::DNS, AnyEvent::Socket, AnyEvent::Handle

example-filter-with-ml

An example filter using Mail::MIMEDefang::ML to get ham/spam/phishing verdicts from a machine-learning model, in addition to the usual SPF, DKIM, DMARC, and SpamAssassin checks. The backend is chosen through $Mail::MIMEDefang::ML::Config{backend}; the filter code is the same for every backend:

| Backend | Model | Server | Typical latency | |------------|-------------------------------------------|----------------------------------------------|-----------------------| | laya | Laya non-autoregressive decision model | mimedefang-laya-server (port 8687) | tens of ms | | gliclass | GLiClass zero-shot encoder (ModernBERT) | mimedefang-gliclass-server (port 8688) | tens of ms | | openai | self-hosted generative model, >= 7-8B parameters (e.g. Qwen3 8B) | Ollama / llama.cpp / vLLM, OpenAI-compatible API | hundreds of ms to seconds |

Laya and GLiClass answer in a single forward pass and are fast enough for every message. The openai backend runs a generative model, so it is slower: the example sets $Mail::MIMEDefang::ML::Config{timeout} to 10 seconds (the module default is 30), which is meant for Laya and GLiClass and must be increased for openai (e.g. to 60; an 8B model on CPU takes seconds per message). Keep timeout * (1 + connect_retries), plus the SpamAssassin run time, below the multiplexor busy timeout (mimedefang-multiplexor -b, default 120 seconds) and the MTA's milter timeouts, or raise those too.

Use a model with at least 7-8 billion parameters (Qwen3 8B, Llama 3.1 8B, Mistral 7B, Gemma 2 9B or larger). Smaller models (1-4B, e.g. Qwen3 1.7B or Phi-3 mini) catch blatant spam and phishing but judge subtler unsolicited mail, such as cold sales pitches, as ham, so they add little on top of SpamAssassin.

Backend URLs can use any host name or IP address. The model servers have no authentication and every request carries message content, so keep them secure by limiting access with a firewall: only the MIMEDefang host(s) should be able to reach their ports, and they should never be exposed to the Internet. mimedefang-laya-server and mimedefang-gliclass-server listen on 127.0.0.1 by default; if you pass --host to make one listen on another address, firewall that port.

Requires: Mail::MIMEDefang::ML, LWP::UserAgent, JSON::PP, and a running backend.

The Laya and GLiClass model servers, with instructions for installing their Python modules, downloading the models, running them under systemd, and sizing them for your multiplexor, are in script/ml-servers/.

redhat-logrotate-file

If you log statistics to /var/log/mimedefang/stats, you want to rotate the log file. You can copy redhat-logrotate-file to /etc/logrotate.d/mimedefang on Red Hat Linux systems.

init-script

A generic /etc/init.d script which should work on most versions of UNIX. Typically, you'd rename it to mimedefang-ctrl and call it from your startup scripts:

mimedefang-ctrl start  -- Start mimedefang
mimedefang-ctrl stop   -- Stop mimedefang
mimedefang-ctrl reread -- Re-read filter rules (if using multiplexor)