#smtp #server #email

mailin

A library for writing SMTP servers

8 releases (4 breaking)

0.5.0 Mar 6, 2021
0.4.1 Aug 25, 2019
0.4.0 Mar 22, 2019
0.3.0 Mar 13, 2019
0.1.2 Dec 28, 2018

#24 in #smtp

Download history 11/week @ 2021-07-04 29/week @ 2021-07-11 52/week @ 2021-07-18 26/week @ 2021-07-25 40/week @ 2021-08-01 20/week @ 2021-08-08 71/week @ 2021-08-15 70/week @ 2021-08-22 27/week @ 2021-08-29 15/week @ 2021-09-05 36/week @ 2021-09-12 37/week @ 2021-09-19 21/week @ 2021-09-26 19/week @ 2021-10-03 33/week @ 2021-10-10 31/week @ 2021-10-17

129 downloads per month
Used in mailin-embedded

MIT/Apache

56KB
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

~2MB
~41K SLoC

oC`