Crates.io | samotop |
lib.rs | samotop |
version | 0.13.2 |
source | src |
created_at | 2018-07-06 19:47:57.117046 |
updated_at | 2022-01-30 00:29:54.226732 |
description | SMTP server and library built on async-std |
homepage | https://gitlab.com/BrightOpen/Samotop/ |
repository | https://gitlab.com/BrightOpen/Samotop/ |
max_upload_size | |
id | 73146 |
size | 104,481 |
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.
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 can be dumped to the console, saved in a folder or passed to a downstream SMTP/LMTP server. After that, you can do it again. See the api docs. The samotop crate is published on crates.io.
viaspf
crate, now asyncPrudence
Impatience
Builder
+ Configuration
+ MailSetup
=> Service
Add this to your Cargo.toml
:
[dependencies.samotop]
version = "0"
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:
TcpServer
) - it takes IP:port's to listen on()
and you can then serve()
your own implementation of a IoService
.UnixServer
) - it takes socket file path to listen on()
and you can then serve()
the same as with the TcpServer
.SmtpParser
) - it takes &[u8]
and returns parsed commands or data.samotop-core
) - these describe the domain and behavior per RFC.samotop-delivery
includes an SMTP/LMTP client over TCP/Unix socket, chid process, simple maildir, sendmail.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 (rustls) and async-native-tls (native-tls).
The samotop-server is a working reference for this TLS setup
where you need to provide only the cert and key.
You can also implement your own TlsProvider
and plug it in.
You can easily run a plaintext SMTP service without support for STARTTLS.
Replace Builder
with your own implementation or compose
a mail service with Builder + mailsetup
and provided features.
Look at samotop-server for a working example with TLS and other features.
extern crate async_std;
extern crate env_logger;
extern crate samotop;
#[async_std::main]
async fn main() {
use samotop::mail::*;
use samotop::smtp::*;
use samotop::server::*;
env_logger::init();
let mail = Builder
+ Esmtp.with(SmtpParser);
let srv = TcpServer::on("localhost:25").serve(mail.build());
srv.await.expect("success")
}
Any TCP service can be served. See the docs for IoService
.
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.
extern crate async_std;
extern crate env_logger;
extern crate samotop;
use samotop::server::TcpServer;
use samotop::io::DummyService;
fn main() {
env_logger::init();
let mut srv = TcpServer::on("localhost:0").serve(DummyService);
async_std::task::block_on(srv).unwrap()
}
You can serve the same on Unix sockets
extern crate async_std;
extern crate env_logger;
extern crate samotop;
use samotop::server::UnixServer;
use samotop::io::DummyService;
fn main() {
env_logger::init();
let mut srv = UnixServer::on("local.socket").serve(DummyService);
async_std::task::block_on(srv).unwrap()
}
You can serve the same on a command line IO. See the on-cmd example.
$ cargo readme > README.md`
In Rust world I have so far found mostly SMTP clients.
MIT OR Apache-2.0
:warning: WARNING: GPLv3 in samotop-parser-nom crate - parser-nom feature of this crate
Since the rustyknife crate is licensed under GPLv3, it's terms apply to you if you distribute a binary including the parser-nom feature.
Unless you explicitly state otherwise, any contribution submitted for inclusion in samotop projects by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.