rok-mail 0.1.0

Email support for the rok ecosystem — Mailable trait, log/SMTP drivers
Documentation

rok-mail

Typed email system for Axum. Define emails as structs implementing Mailable, send via SMTP, Resend, or a log driver for local development.

Installation

[dependencies]
rok-mail = { version = "0.1", features = ["smtp", "axum"] }

Quick Start

use rok_mail::{Mailable, Mail, MailConfig};

pub struct WelcomeEmail {
    pub name: String,
    pub email: String,
}

impl Mailable for WelcomeEmail {
    fn build(&self) -> Mail {
        Mail::new()
            .to(&self.email)
            .subject(format!("Welcome, {}!", self.name))
            .html(format!("<h1>Hi {}!</h1><p>Your account is ready.</p>", self.name))
            .text(format!("Hi {}! Your account is ready.", self.name))
    }
}

// Send
let mailer = MailConfig::smtp("smtp://user:pass@smtp.example.com:587").build();
WelcomeEmail { name: "Alice".into(), email: "alice@example.com".into() }
    .send(&mailer)
    .await?;

Features

Feature Description
smtp SMTP driver (lettre)
resend Resend API driver
axum MailLayer for Axum state injection

Log Driver (development)

// Prints email to stdout instead of sending
let mailer = MailConfig::log().build();

Axum Integration

let app = Router::new()
    .route("/register", post(register))
    .layer(MailLayer::new(mailer));

// In handler:
async fn register(
    State(mailer): State<Arc<dyn MailDriver>>,
    ..
) -> impl IntoResponse {
    WelcomeEmail { .. }.send(&mailer).await?;
}