Send email from Rust
cargo add mailset, then mailset.send(message).await?. The client is async on Tokio, and every command’s input and answer is a struct or an enum that cargo clippy checks.
By starting you agree to the Terms and Privacy Policy.
Install the Rust SDK
cargo, or the line for Cargo.toml. Rust 1.88 and later. It depends on base64, getrandom, hmac, p256, reqwest, serde, serde_json, sha2 and tokio.
cargo add mailset
Send your first email from Rust
Client::from_env()? reads MAILSET_KEY. Message::builder() takes each field, .deliver_by("10m") included, and send(message).await? answers the receipt, sent.id and sent.status. A refusal comes back as a mailset::Error, which ? hands to your caller.
use mailset::{Client, Message};
// Reads MAILSET_KEY from the environment.
let mailset = Client::from_env()?;
let message = Message::builder()
.from("Acme <moc.elpmaxe@olleh>")
.to("gro.elpmaxe@ana")
.subject("Your Acme code")
.text("Your code is 123456.")
.html("<p>Your code is <b>123456</b>.</p>")
.deliver_by("10m");
let sent = mailset.send(message).await?;
println!("{} {:?}", sent.id, sent.status);
Delivery events in Axum
mailset_hook takes the body as Bytes, because a Json extractor would parse it first and the signature covers the bytes as sent. webhooks::verify checks them against the HeaderMap; anything but Ok answers 401. The handler matches Event::Bounced for hard bounces and returns 204 once the batch is kept.
use axum::body::Bytes;
use axum::http::{HeaderMap, StatusCode};
use mailset::webhooks::{self, Event};
// The signature covers the body exactly as it came:
// take it as `Bytes`. A `Json` extractor would parse
// it first and lose the bytes it was made over.
pub async fn mailset_hook(
headers: HeaderMap,
body: Bytes,
) -> StatusCode {
let secret = std::env::var("MAILSET_HOOK_SECRET");
let secret = secret.unwrap_or_default();
let verified =
webhooks::verify(&body, &headers, &secret);
let Ok(events) = verified else {
return StatusCode::UNAUTHORIZED;
};
In the SDK’s tests: compiled against Axum, and run through its router.
Send from your own domain
Your product sends as your own domain either way. What changes is where your team’s mail lives.
- Sending only. Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. Send from a domain whose mail stays elsewhere
- Mailboxes too. Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. Set up a domain
mailset domains add example.com --sendingmailset domains apply example.com --sendingmailset domains check example.commailset keys create --send --domain example.com --from moc.elpmaxe@olleh --name "Acme API"What the Rust SDK’s build checks
Each line comes from the SDK’s own build, which fails when one stops being true.
| Fact | Detail | Known from |
|---|---|---|
| Rust 1.88+ | The oldest its manifest allows | Its manifest |
| Typed throughout | Structs and enums, checked by clippy | A test |
| Every public command | 238 commands, each a typed method | The catalog |
Where to go from here
- The Rust SDKEvery task, from the client’s options to errors and retries.
- WebhooksThe events Mailset posts about your product’s email, and how to check a request’s signature.
- Give sign-in codes a deadlineUse deliverBy so a code that would arrive late is never sent.
- Retry without sending twiceMake a send safe to repeat with an idempotency key or a Message-ID.
- Handle bouncesTell a dead address from a full inbox, and keep your list clean.
- Send many messages at onceUp to 100 messages a request, each with its own answer.
Product email on every plan
- Base$29a month10 members included
- Team$79a month25 members included
- Base
Regular price $29$14.50a month10 members included - Team
Regular price $79$39.50a month25 members included
Black Friday prices, for trials started by Thursday, Dec 31. Offer terms
Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go.
Sending from Rust, asked and answered
Is there a blocking client?
No. Every call is async on Tokio, so run it from an async function: an Axum handler, or a main under #[tokio::main].
Do I need lettre?
No. lettre speaks SMTP, and Mailset takes your product’s email over HTTPS, which the crate calls through reqwest.
Should I clone the client?
Freely. Clones share one connection pool, so a clone per handler or task costs nothing new.
Does it link OpenSSL?
No. reqwest is built with rustls here, so the crate needs no system TLS library.
Make a key and sendTry it on your own domain
Make a key in Settings › Developers, keep it as MAILSET_KEY, and run the example above.7 days free, with everything on. Make a key, run the example above and watch the receipt come back.
By starting you agree to the Terms and Privacy Policy.