A fully asynchronous SMTP server built in Rust implementing core RFC-compliant email protocol commands with TLS, Authentication, and Database-backed mail storage.
This project focuses on building a production-style SMTP server from scratch using the Rust async ecosystem.
EHLO/HELOMAIL FROMRCPT TODATARSETNOOPVRFYHELPQUIT
- STARTTLS support
- AUTH LOGIN authentication
- TLS handshake using
rustls - Authenticated mail submission
- Tokio async TCP server
- Concurrent multi-client handling
- Non-blocking database writes using
spawn_blocking
- Email storage
- Multi-recipient support
- User authentication
- Mailbox listing
- Rust
- Tokio
- Diesel ORM
- SQLite
- rustls
- r2d2 connection pooling
- Axum (API layer — WIP)
Client
│
▼
TCP Server (Tokio)
│
▼
Session State Machine
│
├── TLS Layer
├── Auth Layer
└── SMTP Commands
│
▼
Storage Layer (Diesel)
│
▼
SQLite Database
src/
├── main.rs
├── session.rs
├── parser.rs
├── storage.rs
├── models.rs
├── schema.rs
├── tls.rs
├── config.rs
├── response.rs
└── api/ (WIP)
git clone https://github.com/yourrepo/smtp-server
cd smtp-serverCreate .env file:
DATABASE_URL=emails.dbmkdir certs
openssl req -x509 -newkey rsa:4096 \
-keyout certs/key.pem \
-out certs/cert.pem \
-days 365 -nodescargo runServer runs on:
- SMTP Server:
127.0.0.1:2525 - API Server (WIP):
127.0.0.1:3000
EHLO localhost
STARTTLS
AUTH LOGIN
MAIL FROM:<user@test.com>
RCPT TO:<receiver@test.com>
DATA
Hello world
.
QUIT
Users stored in database:
userstable
Authentication flow:
AUTH LOGIN- Username
- Password
Tables:
usersemailsrecipients
Supports:
- Multi-recipient emails
- Mailbox listing
- Authentication
- SMTP Protocol
- Async TCP Server
- TLS Support
- Authentication
- Database storage
- Multi-recipient emails
- REST API
- UI Dashboard
- Attachments support
- Message Queue
- DKIM/SPF verification
- SMTP relay support
- Production hardening
This project aims to:
- Learn the SMTP protocol deeply
- Build a production-grade Rust networking system
- Understand async Rust architecture
- Build mail infrastructure from scratch
Most developers use email services. This project builds one from scratch.
Focus Areas:
- Async Rust
- Protocol design
- Networking
- Database design
- Security (TLS + Auth)