Quick setup examples

Rust

Send your first email from Rust using reqwest against the MailBlastr API.

MailBlastr has no Rust crate — you send email by POSTing JSON to https://api.mailblastr.com/emails. The example below uses the async `reqwest` client with Tokio.

Prerequisites

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_json

2. Set your API key

.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx

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://api.mailblastr.com/emails")
        .bearer_auth(api_key)
        .json(&json!({
            "from": "Acme <onboarding@yourdomain.com>",
            "to": ["delivered@example.com"],
            "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.