Official Rust SDK for the Lettermint sending and team APIs.
- Current stable Rust. The crate's
rust-versiontracks the current supported stable minor release. - Tokio or another async runtime compatible with
reqwest
[dependencies]
lettermint = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }use lettermint::Lettermint;
#[tokio::main]
async fn main() -> lettermint::Result<()> {
let email = Lettermint::email(std::env::var("LETTERMINT_TOKEN").unwrap())?;
let response = email
.email()
.from("sender@example.com")
.to("recipient@example.com")
.subject("Hello from Rust")
.html("<p>Hello from Lettermint.</p>")
.idempotency_key("welcome-123")
.send()
.await?;
println!("{}", response.message_id);
Ok(())
}The fluent email builder owns its payload. Each call to email.email() starts with a fresh payload, so attachments, headers, metadata, and recipients do not leak between sends.
use lettermint::{types, Lettermint};
#[tokio::main]
async fn main() -> lettermint::Result<()> {
let email = Lettermint::email(std::env::var("LETTERMINT_TOKEN").unwrap())?;
let payload = types::SendMailRequest {
from: "sender@example.com".into(),
to: vec!["recipient@example.com".into()],
subject: "Typed payload".into(),
text: Some("Hello from Lettermint.".into()),
..Default::default()
};
email.send(&payload).await?;
Ok(())
}use lettermint::Lettermint;
#[tokio::main]
async fn main() -> lettermint::Result<()> {
let api = Lettermint::api(std::env::var("LETTERMINT_TEAM_TOKEN").unwrap())?;
let domains = api.domains().list(&[("page[size]", "10")]).await?;
for domain in domains.data {
println!("{}", domain.domain);
}
Ok(())
}Lettermint::email(...) authenticates with X-Lettermint-Token for sending endpoints. Lettermint::api(...) authenticates with Authorization: Bearer ... for team endpoints.
use lettermint::Webhook;
fn handle(payload: &str, signature: &str, delivery: i64) -> lettermint::Result<serde_json::Value> {
Webhook::new(std::env::var("LETTERMINT_WEBHOOK_SECRET").unwrap())
.verify(payload, signature, Some(delivery))
}Webhook verification checks the t=... timestamp, validates the v1=... HMAC-SHA256 signature in constant time, cross-checks the optional delivery timestamp, and enforces a 5 minute tolerance by default.
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features --lockedGenerated DTOs live in src/types.rs. Regenerate them from the repository root with:
python3 sdk-generator/rust/generate-types.py