Quickstarts
Send with Rust
Send email from Rust with the usend crate.
You need a verified domain and an API key.
1. Install
[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
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);
}
}
}USEND_API_KEY=us_123456789 cargo runNotes
- The client retries
429(honoringRetry-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
POSTtohttps://api.usend.et/emailswith anAuthorization: Bearerheader, soreqwestandserde_jsonwork too.
Web framework example: Axum. All fields: Send emails.