| Crates.io | mogimail |
| lib.rs | mogimail |
| version | 0.1.1 |
| created_at | 2025-08-09 09:17:03.978513+00 |
| updated_at | 2025-08-22 00:07:03.853788+00 |
| description | Embedded SMTP server |
| homepage | |
| repository | https://github.com/akar1ngo/mogimail |
| max_upload_size | |
| id | 1787725 |
| size | 111,312 |
MogiMail is an embedded SMTP server for testing.
It enables testing of email code without using mocks.
Add the following to Cargo.toml.
[dev-dependencies]
mogimail = "0.1.1"
use mogimail::SmtpServer;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
#[test]
fn test_email_sending() {
// Create and start the server
let (tx, rx) = mpsc::channel();
let server = SmtpServer::new("test.local");
thread::spawn(move || {
server.start("127.0.0.1:2525", tx).expect("failed starting server");
});
// Execute app code
send_mail("127.0.0.1:2525", "test@example.com", "recipient@example.com", "Test Subject", "Test Body");
// Wait for the server process to complete
let email = rx.recv_timeout(Duration::from_secs(1)).expect("timeout exceeded");
// Check the contents of the sent email
assert_eq!(email.from, "test@example.com");
assert_eq!(email.to, vec!["recipient@example.com"]);
assert!(email.data.contains("Test Subject"));
}
# Start with default settings (localhost:2525)
cargo run
# Start with specified address and hostname
cargo run -- 127.0.0.1:8025 myhost.local
The standalone server will output received emails to standard output in order.
cargo run --example basic_usage
Run the test suite:
cargo test
HELO - Identify the senderMAIL FROM - Specify the sender's addressRCPT TO - Specify the destination (multiple destinations are supported)DATA - Send the bodyRSET - Reset the current transactionNOOP - Do nothingQUIT - Close connectionThis library is licensed under the MIT License. See the LICENSE file for details.