rusted-mail 0.1.2

Protocol and storage engine for IMAP, SMTP, POP3, and JMAP mail clients
Documentation

rusted-mail

rusted-mail is a typed, asynchronous protocol and storage engine for mail applications. It provides IMAP, SMTP, POP3, JMAP, provider discovery, local storage, offline operations, and optional OpenPGP/S/MIME support without linking JNI or an Android runtime.

Quick start

use rusted_mail::{
    AccountConfig, Credentials, FetchOptions, MailEngine, Message,
    ServerConfig,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let account = AccountConfig::builder("alice@example.com")
        .credentials(Credentials::password("application-password"))
        .imap(ServerConfig::tls("imap.example.com", 993))
        .smtp(ServerConfig::start_tls("smtp.example.com", 587))
        .build()?;

    let engine = MailEngine::new();
    let session = engine.connect_imap(account).await?;

    let _mailboxes = session.list_mailboxes().await?;
    let _messages = session
        .fetch(FetchOptions::new("1:*").mailbox("INBOX").limit(50))
        .await?;

    let message = Message::builder()
        .to("bob@example.com")
        .subject("Hello")
        .text("Sent with rusted-mail")
        .build()?;
    session.send(message).await?;
    session.close().await?;
    Ok(())
}

The API also exposes owned Pop3Session and JmapSession handles, typed message actions, attachment helpers, mailbox management, searches, and provider discovery.

POP3 retrieval

use rusted_mail::{
    BodyOptions, Credentials, MailEngine, Pop3AccountConfig, Pop3ServerConfig,
};

# async fn example() -> Result<(), rusted_mail::Error> {
let account = Pop3AccountConfig::builder("alice@example.com")
    .credentials(Credentials::password("application-password"))
    .server(Pop3ServerConfig::tls("pop.example.com", 995))
    .build()?;

let session = MailEngine::new().connect_pop3(account).await?;
for info in session.list().await? {
    let message = session
        .retrieve(info.sequence_number, BodyOptions::default())
        .await?;
    println!("{:?}", message.body.subject);
}
session.close().await?;
# Ok(())
# }

Pop3ServerConfig::start_tls upgrades with STLS. The explicit plain_text constructor is intended only for trusted, isolated test fixtures. Private/local endpoints and nonstandard ports also require exact opt-in with MailEngine::builder().allow_private_network_target(...).allow_port(...).

Private certificate authorities can be added without disabling hostname verification by calling MailEngine::builder().add_trusted_root_certificate_der(...). The added root is used consistently by JMAP HTTPS, IMAP TLS, SMTP TLS, and POP3 TLS.

Features

  • turso-native-sync enables Turso native synchronization.
  • crypto-openpgp enables OpenPGP processing.
  • crypto-smime enables S/MIME processing.

No optional feature is enabled by default.

Runtime

The crate uses Tokio and integrates with tracing. Applications own the async runtime; rusted-mail operations are ordinary async methods. Configure optional engine defaults with MailEngine::builder().

JNI and Android packaging live in the sibling rusted-mail-jni and rusted-mail-android packages.