copilot/add-pop3-protocol-implementation
Mail Server (SMTP + POP3)
A basic mail server implementation in Rust with SMTP and POP3 protocol support, featuring TLS/STARTTLS support.
Features
SMTP Server
- ✅ Basic SMTP protocol support (HELO/EHLO, MAIL FROM, RCPT TO, DATA, QUIT)
- ✅ STARTTLS support for secure connections
- ✅ Self-signed certificate generation for TLS
- ✅ Multiple recipient support
- ✅ Command validation and error handling
POP3 Server
- ✅ Complete POP3 protocol implementation (RFC 1939)
- ✅ User authentication (USER/PASS commands)
- ✅ Message retrieval (STAT, LIST, RETR commands)
- ✅ Message deletion (DELE, RSET commands)
- ✅ Session management (QUIT command with update state)
- ✅ Capability advertisement (CAPA command)
- ✅ Keep-alive support (NOOP command)
General
- ✅ Async/await with Tokio runtime
- ✅ Structured logging with tracing
- ✅ Shared message storage between protocols
- ✅ Concurrent server operation
Running the Server
cargo run
The servers listen on:
- SMTP: 127.0.0.1:2525
- POP3: 127.0.0.1:2110
Testing
SMTP Testing
You can test the SMTP server using nc (netcat) or telnet:
echo -e "EHLO test.com\r\nMAIL FROM: <sender@example.com>\r\nRCPT TO: <recipient@example.com>\r\nDATA\r\nSubject: Test\r\n\r\nTest message\r\n.\r\nQUIT\r\n" | nc localhost 2525
POP3 Testing
Test POP3 commands:
# List messages
echo -e "USER test\r\nPASS password\r\nLIST\r\nQUIT\r\n" | nc localhost 2110
# Retrieve a message
echo -e "USER test\r\nPASS password\r\nRETR 1\r\nQUIT\r\n" | nc localhost 2110
# Check mailbox statistics
echo -e "USER test\r\nPASS password\r\nSTAT\r\nQUIT\r\n" | nc localhost 2110
# Delete a message
echo -e "USER test\r\nPASS password\r\nDELE 1\r\nQUIT\r\n" | nc localhost 2110
Supported Commands
SMTP Commands
HELO/EHLO- Initiate SMTP sessionMAIL FROM- Specify sender email addressRCPT TO- Specify recipient email address (supports multiple)DATA- Begin email message contentRSET- Reset the current transactionNOOP- No operation (keepalive)QUIT- Close connectionSTARTTLS- Upgrade connection to TLS
POP3 Commands
USER- Specify username for authenticationPASS- Provide password for authenticationSTAT- Get mailbox statistics (message count and total size)LIST- List messages with sizes (all or specific message)RETR- Retrieve a specific messageDELE- Mark a message for deletionNOOP- No operation (keep-alive)RSET- Reset session (unmark deleted messages)QUIT- End session and apply deletionsCAPA- List server capabilities
Building
cargo build --release
Dependencies
tokio- Async runtimeanyhow- Error handlingtracing/tracing-subscriber- Loggingregex- SMTP command parsingnative-tls/tokio-native-tls- TLS supportopenssl- Certificate generationfutures- Stream handlingtokio-util- Codec utilities