|
1
|
# Mail Server (SMTP + POP3) |
|
2
|
|
|
3
|
A basic mail server implementation in Rust with SMTP and POP3 protocol support, featuring TLS/STARTTLS support. |
|
4
|
|
|
5
|
## Features |
|
6
|
|
|
7
|
### SMTP Server |
|
8
|
- ✅ Basic SMTP protocol support (HELO/EHLO, MAIL FROM, RCPT TO, DATA, QUIT) |
|
9
|
- ✅ STARTTLS support for secure connections |
|
10
|
- ✅ Self-signed certificate generation for TLS |
|
11
|
- ✅ Multiple recipient support |
|
12
|
- ✅ Command validation and error handling |
|
13
|
|
|
14
|
### POP3 Server |
|
15
|
- ✅ Complete POP3 protocol implementation (RFC 1939) |
|
16
|
- ✅ User authentication (USER/PASS commands) |
|
17
|
- ✅ Message retrieval (STAT, LIST, RETR commands) |
|
18
|
- ✅ Message deletion (DELE, RSET commands) |
|
19
|
- ✅ Session management (QUIT command with update state) |
|
20
|
- ✅ Capability advertisement (CAPA command) |
|
21
|
- ✅ Keep-alive support (NOOP command) |
|
22
|
|
|
23
|
### General |
|
24
|
- ✅ Async/await with Tokio runtime |
|
25
|
- ✅ Structured logging with tracing |
|
26
|
- ✅ Shared message storage between protocols |
|
27
|
- ✅ Concurrent server operation |
|
28
|
|
|
29
|
## Running the Server |
|
30
|
|
|
31
|
```bash |
|
32
|
cargo run |
|
33
|
``` |
|
34
|
|
|
35
|
The servers listen on: |
|
36
|
- SMTP: `127.0.0.1:2525` |
|
37
|
- POP3: `127.0.0.1:2110` |
|
38
|
|
|
39
|
## Testing |
|
40
|
|
|
41
|
### SMTP Testing |
|
42
|
|
|
43
|
You can test the SMTP server using `nc` (netcat) or `telnet`: |
|
44
|
|
|
45
|
```bash |
|
46
|
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 |
|
47
|
``` |
|
48
|
|
|
49
|
### POP3 Testing |
|
50
|
|
|
51
|
Test POP3 commands: |
|
52
|
|
|
53
|
```bash |
|
54
|
# List messages |
|
55
|
echo -e "USER test\r\nPASS password\r\nLIST\r\nQUIT\r\n" | nc localhost 2110 |
|
56
|
|
|
57
|
# Retrieve a message |
|
58
|
echo -e "USER test\r\nPASS password\r\nRETR 1\r\nQUIT\r\n" | nc localhost 2110 |
|
59
|
|
|
60
|
# Check mailbox statistics |
|
61
|
echo -e "USER test\r\nPASS password\r\nSTAT\r\nQUIT\r\n" | nc localhost 2110 |
|
62
|
|
|
63
|
# Delete a message |
|
64
|
echo -e "USER test\r\nPASS password\r\nDELE 1\r\nQUIT\r\n" | nc localhost 2110 |
|
65
|
``` |
|
66
|
|
|
67
|
## Supported Commands |
|
68
|
|
|
69
|
### SMTP Commands |
|
70
|
- `HELO/EHLO` - Initiate SMTP session |
|
71
|
- `MAIL FROM` - Specify sender email address |
|
72
|
- `RCPT TO` - Specify recipient email address (supports multiple) |
|
73
|
- `DATA` - Begin email message content |
|
74
|
- `RSET` - Reset the current transaction |
|
75
|
- `NOOP` - No operation (keepalive) |
|
76
|
- `QUIT` - Close connection |
|
77
|
- `STARTTLS` - Upgrade connection to TLS |
|
78
|
|
|
79
|
### POP3 Commands |
|
80
|
- `USER` - Specify username for authentication |
|
81
|
- `PASS` - Provide password for authentication |
|
82
|
- `STAT` - Get mailbox statistics (message count and total size) |
|
83
|
- `LIST` - List messages with sizes (all or specific message) |
|
84
|
- `RETR` - Retrieve a specific message |
|
85
|
- `DELE` - Mark a message for deletion |
|
86
|
- `NOOP` - No operation (keep-alive) |
|
87
|
- `RSET` - Reset session (unmark deleted messages) |
|
88
|
- `QUIT` - End session and apply deletions |
|
89
|
- `CAPA` - List server capabilities |
|
90
|
|
|
91
|
## Building |
|
92
|
|
|
93
|
```bash |
|
94
|
cargo build --release |
|
95
|
``` |
|
96
|
|
|
97
|
## Dependencies |
|
98
|
|
|
99
|
- `tokio` - Async runtime |
|
100
|
- `anyhow` - Error handling |
|
101
|
- `tracing` / `tracing-subscriber` - Logging |
|
102
|
- `regex` - SMTP command parsing |
|
103
|
- `native-tls` / `tokio-native-tls` - TLS support |
|
104
|
- `openssl` - Certificate generation |
|
105
|
- `futures` - Stream handling |
|
106
|
- `tokio-util` - Codec utilities |