Expand description
§MogiMail
MogiMail is an embedded SMTP server for testing.
It enables testing of email code without using mocks.
§Quick Start
use mogimail::SmtpServer;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
// Create and start server
let (tx, rx) = mpsc::channel();
let server = SmtpServer::new("test.local");
thread::spawn(move || {
server.start("127.0.0.1:2525", tx).unwrap();
});
// Application sends email to localhost:2525
// ...
// Check the contents of the sent email
if let Ok(email) = rx.recv_timeout(Duration::from_millis(100)) {
println!("Received email from: {}", email.from);
}§Supported SMTP commands
HELO- Identify the senderMAIL FROM- Specify the sender’s addressRCPT TO- Specify the destination (multiple destinations are supported)DATA- Send the email bodyRSET- Reset the current transactionNOOP- Do nothingQUIT- Close connection
§Additional Features
Enabling the ehlo feature also allows you to use the EHLO command.
§Notes
- Only the “minimal implementation” defined in RFC 821 is implemented.
- Runs in-memory only. Email persistence is not supported.
- SMTP authentication is not supported.
- SSL/TLS connection is not supported.
- Mail relay is not supported.
§Size Limits
The server enforces RFC 821 size limits:
- User names: 64 characters max
- Domain names: 64 characters max
- Paths: 256 characters max
- Command lines: 512 characters max
- Text lines: 1000 characters max
- Recipients: 100 max per message
§Email Handling
Emails are sent directly to the channel provided when starting the server.
Use recv_timeout() on the receiver to wait for emails with a timeout.
This avoids the need for thread::sleep() and provides deterministic
behavior when testing email functionality.
Structs§
- Represents an email message received by the SMTP server
- Smtp
Limits - SMTP size limits as defined in RFC 821
- Smtp
Response - Represents an SMTP response that can be sent to a client
- Smtp
Server - Main SMTP server that handles connections and sends emails to a channel
- Smtp
Session - Manages the state and data for a single SMTP session