Guide · Go, Rust & JVM
How to send email with Rust
Send email from Rust with reqwest and serde_json, or with the lettre crate over SMTP.
Last reviewed November 2026
1. Set up
You need a Stack Emails API key (create one free) and a verified sending domain.
# Cargo.toml
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
2. Send your first email
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let key = std::env::var("STACKEMAILS_API_KEY").expect("STACKEMAILS_API_KEY not set");
let res = reqwest::Client::new()
.post("https://stackemails.com/v1/emails")
.bearer_auth(key)
.json(&json!({
"from": "Acme <hello@mail.acme.com>",
"to": "ada@example.com",
"subject": "Welcome to Acme",
"html": "<p>Thanks for signing up!</p>"
}))
.send()
.await?;
println!("{} {}", res.status(), res.text().await?);
Ok(())
}
A successful request returns 202 with the message id, for example { "id": "msg_5b1f0c6c2a8e4e0f", "status": "queued" }. Errors return a JSON body with error.code and error.message (see errors).
Production checklist
- Keep the API key in an environment variable or secret manager, never in client-side code.
- Add an
Idempotency-Keyheader to retries so a timeout never sends twice (idempotency). - Subscribe to webhooks for bounces and complaints.
- Check your domain's SPF, DKIM and DMARC records.
- Start from a tested email template for password resets, receipts and invites.