| Crates.io | mailledger-smtp |
| lib.rs | mailledger-smtp |
| version | 0.0.2 |
| created_at | 2026-01-14 14:09:01.425702+00 |
| updated_at | 2026-01-17 17:33:56.323182+00 |
| description | Production-quality SMTP client library implementing RFC 5321 |
| homepage | https://github.com/mqasimca/mailledger |
| repository | https://github.com/mqasimca/mailledger |
| max_upload_size | |
| id | 2042881 |
| size | 77,785 |
Production-quality SMTP client library implementing RFC 5321.
use mailledger_smtp::{Client, Address};
use mailledger_smtp::connection::connect;
#[tokio::main]
async fn main() -> mailledger_smtp::Result<()> {
// Connect to SMTP server
let stream = connect("smtp.example.com", 587).await?;
let mut client = Client::from_stream(stream).await?;
// Send EHLO
let client = client.ehlo("client.example.com").await?;
// Upgrade to TLS
let client = client.starttls("smtp.example.com").await?;
// Authenticate
let client = client.auth_plain("user@example.com", "password").await?;
// Send email
let from = Address::new("sender@example.com")?;
let to = Address::new("recipient@example.com")?;
let client = client.mail_from(from).await?;
let client = client.rcpt_to(to).await?;
let client = client.data().await?;
let message = b"Subject: Test\r\n\r\nHello, World!\r\n";
let client = client.send_message(message).await?;
client.quit().await?;
Ok(())
}
The library uses the type-state pattern to enforce valid SMTP operations:
┌──────────────┐
│ Connected │ ─── auth_plain() ───→ Authenticated
└──────────────┘
│
└─── mail_from() ───→ MailTransaction ───→ RecipientAdded ───→ Data
MIT License - see LICENSE for details.