mailledger-smtp

Crates.iomailledger-smtp
lib.rsmailledger-smtp
version0.0.2
created_at2026-01-14 14:09:01.425702+00
updated_at2026-01-17 17:33:56.323182+00
descriptionProduction-quality SMTP client library implementing RFC 5321
homepagehttps://github.com/mqasimca/mailledger
repositoryhttps://github.com/mqasimca/mailledger
max_upload_size
id2042881
size77,785
Qasim (mqasimca)

documentation

README

mailledger-smtp

Production-quality SMTP client library implementing RFC 5321.

Features

  • Type-state connection management: Compile-time enforcement of valid SMTP state transitions
  • Full protocol support: EHLO, MAIL FROM, RCPT TO, DATA, AUTH, STARTTLS
  • TLS support: Both implicit TLS (port 465) and STARTTLS
  • Authentication: PLAIN, LOGIN, XOAUTH2, OAUTHBEARER
  • Extensions: 8BITMIME, SIZE, PIPELINING, SMTPUTF8

Quick Start

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(())
}

Connection States

The library uses the type-state pattern to enforce valid SMTP operations:

┌──────────────┐
│  Connected   │ ─── auth_plain() ───→ Authenticated
└──────────────┘
       │
       └─── mail_from() ───→ MailTransaction ───→ RecipientAdded ───→ Data

License

MIT License - see LICENSE for details.

Commit count: 6

cargo fmt