Send Emails with Rust
Learn how to send transactional emails using PostStack and Rust.
1. Install the SDK
bash
# Cargo.toml
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }2. Initialize the client
rust
use reqwest::Client;
let client = Client::new();
let api_key = "sk_live_...";3. Send an email
rust
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("POSTSTACK_API_KEY")?;
let response = Client::new()
.post("https://api.poststack.dev/v1/emails")
.header("Authorization", format!("Bearer {}", api_key))
.json(&json!({
"from": "hello@yourdomain.com",
"to": "user@example.com",
"subject": "Hello from Rust!",
"html": "<h1>Welcome!</h1>"
}))
.send()
.await?;
println!("{}", response.text().await?);
Ok(())
}Notes
- Uses reqwest for HTTP requests — the most popular Rust HTTP client
Ready to send emails with Rust?
Create a free account and get your API key in under a minute.