Quick setup examples
Rust
Send your first email from Rust using reqwest against the MailBlastr API.
MailBlastr ships an official Rust crate (cargo add mailblastr) — see Send emails with Rust for the typed, async client — but you do not need it: this guide sends email by POSTing JSON to https://www.mailblastr.com/api/emails. The example below uses the async `reqwest` client with Tokio.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
- An async runtime — Tokio below; any executor that can drive
reqwestfutures works. - Rust 1.75 or newer if you add the official
mailblastrcrate, which declares that as itsrust-version.
1. Create a project and add dependencies
Create a Cargo project and add an async HTTP client plus a runtime.
cargo init mailblastr-rust-example
cd mailblastr-rust-example
cargo add reqwest -F json
cargo add tokio -F macros,rt-multi-thread
cargo add serde_json2. Set your API key
export MAILBLASTR_API_KEY=mb_xxxxxxxxxRust does not read
.env files on its own, and the example below calls std::env::var directly. Export the variable in your shell, or add `dotenvy` (cargo add dotenvy) and call dotenvy::dotenv().ok(); as the first line of main.3. Send email
src/main.rs
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("MAILBLASTR_API_KEY")?;
let res = reqwest::Client::new()
.post("https://www.mailblastr.com/api/emails")
.bearer_auth(api_key)
// REQUIRED: reqwest sends no User-Agent of its own, and the API answers
// a request without one with 403 validation_error before it authenticates.
.header("User-Agent", "my-app/1.0")
.json(&json!({
"from": "Acme <onboarding@yourdomain.com>",
"to": ["delivered@mailblastr.dev"],
"subject": "Hello World",
"html": "<strong>It works!</strong>",
}))
.send()
.await?;
let body: serde_json::Value = res.json().await?;
println!("{}", body["id"]);
Ok(())
}Inside an Axum app, send this request from a handler. See Send an email for the full body schema.