Build Status Maintenance

samotop 0.9.1

This is an SMTP server library with focus on privacy. There is also an actual SMTP server - see samotop-server.

SMTP Server (Relay/MTA, Delivery/MDA) library for Rust with focus on spam elimination and privacy. The motivation is to revive e-mail infrastructure and architecture, address current problems and allow new systems to integrate SMTP. It's called SaMoToP, which could be a nice Czech word.

Status

Reaching stable. You can implement your own mail service and plug it in, focusing on features and not the protocol itself or boilerplate. The API builds on async/await to offer a convenient asynchronous interface. We've got a decent SMTP command parser written as a PEG grammar. The model is tightly nit from the RFCs. An async-std based server will hear your SMTP commands, drive the SMTP state machine and correct you if you step aside. Once a mail session is ready, the mail data are currently dumped to the console. After that, you can do it again. See the api dosc. The samotop crate is published on crates.io.

Done

To do

Installation

Add this to your Cargo.toml:

toml [dependencies.samotop] version = "0"

Usage

See the docs on docs.rs.

Note that the API is still unstable. Please use the latest release.

There are a few interesting provisions one could take away from Samotop: * The server (through samotop::server::Server) - it takes IP:port's to listen on() and you can then serve() your own implementation of a TcpService. * The SMTP service (SmtpService) - it takes an async IO and provides an SMTP service defined by SessionService. * The low level SmtpCodec - it translates between IO and a Stram of ReadControl and a Sink of WriteControl. It handles SMTP mail data as well. * The SMTP session parser (SmtpParser) - it takes &[u8] and returns parsed commands or session. * The SMTP session and domain model (in samotop::model) - these describe the domain and behavior. * Extensible design - you can plug in or compose your own solution.

SMTP Server (with STARTTLS)

Running an SMTP server with STARTTLS support is a bit more involved regarding setting up the TLS configuration. The library includes a TlsProvider implementation for async-tls and rustls. The samotop-server is a working reference for this TLS setup where you needto provide only the cert and key. You can also implement your own TlsProvider and plug it in.

SMTP Server (plaintext)

You can easily run a plaintext SMTP service without support for STARTTLS. Replace DefaultMailService with your own implementation or compose a mail service with CompositeMailService and provided features.

rust extern crate async_std; extern crate env_logger; extern crate samotop; use samotop::server::Server; use samotop::service::tcp::dummy::DummyTcpService; fn main() { env_logger::init(); let mail = samotop::service::mail::default::DefaultMailService; let sess = samotop::service::session::StatefulSessionService::new(mail); let svc = samotop::service::tcp::SmtpService::new(sess); let svc = samotop::service::tcp::TlsEnabled::disabled(svc); let srv = samotop::server::Server::on("localhost:25").serve(svc); async_std::task::block_on(srv).unwrap() }

Dummy server

Any TCP service can be served. See the docs for TcpService. Run it with RUST_LOG=trace to display trace log. Use this to understand how networking IO is handled. Start here to build an SMTP service from scratch step by step.

rust extern crate async_std; extern crate env_logger; extern crate samotop; use samotop::server::Server; use samotop::service::tcp::dummy::DummyTcpService; fn main() { env_logger::init(); let mut srv = Server::on("localhost:0").serve(DummyTcpService); async_std::task::block_on(srv).unwrap() }

Development

Company

In Rust world I have so far found mostly SMTP clients.

SMTP server implementations and libs

Other

License

MIT