[][src]Crate mailin

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

This example is not tested
// 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 and strip the trailing /r/n
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
}

Structs

Response

Response contains a code and message to be sent back to the client

Session

A single smtp session connected to a single client

SessionBuilder

Builds an smtp Session

Enums

Action

Action indicates the recommended action to take on a response

AuthMechanism

Supported authentication mechanisms

AuthResult

AuthResult is the result of authenticating a smtp session

DataResult

DataResult is the result of an smtp DATA command

HeloResult

HeloResult is the result of an smtp HELO or EHLO command

MailResult

MailResult is the result of an smtp MAIL command

RcptResult

RcptResult is the result of an smtp RCPT command

Traits

Handler

A Handler makes decisions about incoming mail commands.