|
1
|
use anyhow::Result; |
|
2
|
use smbcloud_mail::{listen::listen, storage::MessageStorage, mail_mode::MailMode}; |
|
3
|
|
|
4
|
#[tokio::main] |
|
5
|
async fn main() -> Result<()> { |
|
6
|
// Initialize tracing subscriber for logging |
|
7
|
tracing_subscriber::fmt::init(); |
|
8
|
|
|
9
|
// Create shared message storage |
|
10
|
let storage = MessageStorage::new(); |
|
11
|
|
|
12
|
// Clone storage for IMAP server |
|
13
|
let imap_storage = storage.clone(); |
|
14
|
|
|
15
|
// Start IMAP server in a separate task |
|
16
|
tokio::spawn(async move { |
|
17
|
if let Err(err) = smbcloud_mail::imap::listen::listen(imap_storage.mailbox_store).await { |
|
18
|
tracing::error!("IMAP server error: {:?}", err); |
|
19
|
} |
|
20
|
}); |
|
21
|
|
|
22
|
// Clone storage for submission SMTP server (port 2526) |
|
23
|
let submit_storage = storage.clone(); |
|
24
|
|
|
25
|
// Start submission SMTP server (port 2526) in a separate task |
|
26
|
// Port 2526: Mail submission port for outgoing mail |
|
27
|
// - Used by mail clients to submit outgoing messages |
|
28
|
// - Messages are logged and would be relayed to external mail servers |
|
29
|
// - In Submit mode, messages are not stored in INBOX |
|
30
|
tokio::spawn(async move { |
|
31
|
if let Err(err) = listen(submit_storage, 2526, MailMode::Submit).await { |
|
32
|
tracing::error!("SMTP submission server error: {:?}", err); |
|
33
|
} |
|
34
|
}); |
|
35
|
|
|
36
|
// Start receiving SMTP server (port 2525) - this will block |
|
37
|
// Port 2525: Mail receiving port for incoming mail |
|
38
|
// - Used to receive incoming messages from other mail servers |
|
39
|
// - Messages are stored in the INBOX mailbox |
|
40
|
// - In Receive mode, messages are persisted for IMAP access |
|
41
|
listen(storage, 2525, MailMode::Receive).await |
|
42
|
} |