#milter #postfix #sendmail #smtp


Asynchronous milter library

9 releases

0.2.0 Jan 9, 2023
0.2.0-alpha.1 Oct 31, 2022
0.1.1 May 4, 2022
0.1.0 Feb 11, 2022
0.0.1 Oct 17, 2021

#332 in Email

Download history 5/week @ 2023-06-07 30/week @ 2023-06-14 49/week @ 2023-06-21 36/week @ 2023-06-28 39/week @ 2023-07-05 15/week @ 2023-07-12 35/week @ 2023-07-19 20/week @ 2023-07-26 17/week @ 2023-08-02 19/week @ 2023-08-09 26/week @ 2023-08-16 29/week @ 2023-08-23 8/week @ 2023-08-30 45/week @ 2023-09-06 22/week @ 2023-09-13 27/week @ 2023-09-20

102 downloads per month
Used in 4 crates




independent async milter library for Rust

  • pure, safe Rust library for writing milters
  • asynchronous implementation based on Tokio
  • no dependency on libmilter C library
  • fully compatible with existing milter-aware MTAs

The indymilter library provides facilities for creating milters in pure asynchronous Rust. A milter is a mail filtering application that can be integrated with MTAs (mail servers) such as Postfix.

The main advantage of indymilter over similar libraries is its wholehearted adoption of the asynchronous paradigm, which enables virtually unlimited concurrency. An arbitrary number of MTA connections can be handled concurrently by a small number of threads. Internally, the library is based on Tokio.

This library is an implementation of the milter side of the sendmail milter protocol. As such, it assumes the place of the libmilter C library distributed with sendmail. It has no dependency on that library but is a stand-alone, pure, safe (no unsafe) Rust product.

As libmilter is the standard implementation of the venerable milter protocol, indymilter mimics its behaviour accurately. In order to guarantee perfect compatibility with existing MTAs, indymilter aims for bug-for-bug compatibility rather than a fancy ‘modern’ reimagining of the protocol. Questions about the indymilter source code can be answered by looking at the libmilter source.


To use indymilter, add it as a dependency in Cargo.toml. Further usage information can be found in the following places:

For an overview of the protocol design and detailed API functionality, see the original sendmail milter API documentation. This documentation can be found in the sendmail package of your distro (for example, on Debian and Ubuntu at /usr/share/doc/sendmail-doc/libmilter/html/index.html), or directly in the sendmail source tarball at ftp://ftp.sendmail.org/pub/sendmail.

The above is important: While indymilter provides an API similar to libmilter, it does not duplicate documentation for the entire API. For details you will need to check the sendmail docs.


Here is a simple but complete milter program that logs client IP addresses:

use indymilter::{Callbacks, Context, SocketInfo, Status};
use tokio::{net::UnixListener, signal};

async fn main() {
    let listener = UnixListener::bind("/run/ipmilter.sock")
        .expect("cannot open milter socket");

    let callbacks = Callbacks::new()
        .on_connect(|context, _, socket_info| {
            Box::pin(handle_connect(context, socket_info))

    let config = Default::default();

    indymilter::run(listener, callbacks, config, signal::ctrl_c())
        .expect("milter execution failed");

async fn handle_connect(
    _: &mut Context<()>,
    socket_info: SocketInfo,
) -> Status {
    if let SocketInfo::Inet(addr) = socket_info {
        println!("connect from {}", addr.ip());


The above milter will try to open a UNIX domain socket at /run/ipmilter.sock, and will then process incoming MTA connections until it is shut down with Control-C.


Copyright © 2021–2023 David Bürgin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.


~136K SLoC