14 releases

0.6.5 Aug 31, 2024
0.6.4 Feb 10, 2024
0.6.3 May 20, 2023
0.6.1 Jun 6, 2022
0.1.2 Dec 28, 2018

#29 in Email

Download history 300/week @ 2024-07-30 208/week @ 2024-08-06 206/week @ 2024-08-13 284/week @ 2024-08-20 465/week @ 2024-08-27 533/week @ 2024-09-03 302/week @ 2024-09-10 172/week @ 2024-09-17 422/week @ 2024-09-24 493/week @ 2024-10-01 323/week @ 2024-10-08 386/week @ 2024-10-15 325/week @ 2024-10-22 300/week @ 2024-10-29 389/week @ 2024-11-05 360/week @ 2024-11-12

1,459 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

68KB
1.5K SLoC

Mailin

This is a library for writing SMTP servers in Rust. The library handles parsing, the SMTP state machine and building responses.

Programs using the Mailin library are responsible for all IO including opening sockets and storing messages. Mailin makes the lifecycle of an SMTP session available by calling methods on an object that implements the Handler trait.


lib.rs:

A library for building smtp servers.

The library supplies a parser and SMTP state machine. The user of the library supplies I/O code and a Handler implementation for controlling SMTP sessions.

The code using the library, sends lines received to the Session.process_line() method. The user also supplies a Handler implementation that makes decisions on whether to accept or reject email messages. After consulting the Handler the Session.process_line() function will return a response that can be sent back to the email client.

Pseudo Code

// Create a handler which will control the SMTP session
let hander = create_handler();

// Create a SMTP session when a new client connects
let session = SessionBuilder::new("mailserver_name").build(client_ip, handler);

// Read a line from the client
let line = read_line(tcp_connection);
// Send the line to the session
let res = session.process(line);

// Act on the response
match res.action {
    Action::Reply => {
        write_response(tcp_connection, &res)?;
    }
    Action::Close => {
        write_response(tcp_connection, &res)?;
        close(tcp_connection);
    }
    Action::NoReply => (), // No response needed
}

Dependencies

~1.5MB
~26K SLoC