uSend Docs
Quickstarts

Send with Rust

Send email from Rust with the usend crate.

You need a verified domain and an API key.

1. Install

Cargo.toml
[dependencies]
usend = { version = "0.1", features = ["ureq"] }

The crate is blocking and needs no async runtime. Its only required dependencies are serde and serde_json. The ureq feature adds the HTTPS transport; use features = ["reqwest"] if your project already uses reqwest, or implement the Transport trait for your own client.

2. Send

src/main.rs
use usend::{Client, Error, SendEmail};

fn main() {
    let client = Client::from_env().expect("set USEND_API_KEY");

    let email = SendEmail::new("Acme <[email protected]>", ["[email protected]"])
        .subject("Hello from usend")
        .html("<p>It works!</p>")
        .idempotency_key("welcome-ann-1");

    match client.emails().send(&email) {
        Ok(sent) => println!("queued {}", sent.id),
        Err(Error::Api(e)) => {
            eprintln!("usend {} {}: {}", e.status_code, e.name, e.message);
            std::process::exit(1);
        }
        Err(e) => {
            eprintln!("failed: {e}");
            std::process::exit(1);
        }
    }
}
Shell
USEND_API_KEY=us_123456789 cargo run

Notes

  • The client retries 429 (honoring Retry-After) and, for requests with an idempotency key, 5xx (Idempotency).
  • Attachments: .attachment(usend::Attachment::new("a.pdf", &bytes)) (Attachments).
  • Webhooks: usend::verify_webhook(&body, |name| /* header lookup */, secret) (Verify signatures).
  • No crate? The API is one JSON POST to https://api.usend.et/emails with an Authorization: Bearer header, so reqwest and serde_json work too.

Web framework example: Axum. All fields: Send emails.