rok-mail
Typed email framework for Axum — SMTP, Resend, and Postmark drivers with HTML + plain text templates.
Part of the Rok Framework — a full-stack Rust web framework built on Axum 0.8 and SQLx 0.8.
Features
Mailabletrait for defining emails as plain Rust structs with builder-styleMailconstructionMail::send(mailable, recipient).await?one-liner dispatch- SMTP driver via
lettrewith TLS support and connection pooling - Resend API driver for transactional email at scale
- Postmark API driver for high-deliverability transactional email
- Log driver for local development — prints email content to stdout instead of sending
MailLayerTower middleware for injecting the mailer into Axum handlers viaState- Queue integration:
mailable.queue().await?dispatches sending as a background job viarok-queue
Installation
[]
= { = "0.2", = ["smtp", "axum"] }
Quick Start
use ;
use ;
use Arc;
async
Core API
Mail builder
let mail = new
.to
.cc
.bcc
.reply_to
.from
.subject
.html
.text
.attach_path
.header;
Driver configuration
use MailConfig;
// SMTP
let mailer = smtp
.from
.from_name
.build?;
// Resend
let mailer = resend
.from
.build?;
// Postmark
let mailer = postmark
.from
.build?;
// Log (development)
let mailer = log.build;
Queue integration
// Send in the background via rok-queue instead of blocking the request
WelcomeEmail
.queue
.await?;
// returns immediately — email is sent by a queue worker
// Delayed send
WelcomeEmail
.queue_in
.await?;
Feature Flags
| Flag | Description | Default |
|---|---|---|
smtp |
SMTP driver via lettre |
No |
resend |
Resend API driver | No |
postmark |
Postmark API driver | No |
axum |
MailLayer middleware and State<Arc<dyn MailDriver>> support |
No |
queue |
Mailable::queue() integration with rok-queue |
No |
Integration
rok-mail is used by rok-auth for email verification and password reset flows, and by rok-notification for the email channel. Configure the mailer once and inject it via MailLayer:
let mailer = smtp.from.build?;
let app = new
.route
.layer;
License
MIT