Setup
Copy
Ask AI
# Cargo.toml
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
Send an email
Copy
Ask AI
use serde::{Deserialize, Serialize};
#[derive(Serialize)]
struct SendEmail {
from: String,
to: Vec<String>,
subject: String,
html: Option<String>,
}
#[derive(Deserialize)]
struct EmailResponse {
id: String,
}
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = reqwest::Client::new();
let email = SendEmail {
from: "you@yourdomain.com".into(),
to: vec!["user@example.com".into()],
subject: "Hello from Sendi".into(),
html: Some("<p>It just works.</p>".into()),
};
let res: EmailResponse = client
.post("https://app.usesendi.com/api/emails")
.header("Authorization", "Bearer snd_your_api_key")
.json(&email)
.send()
.await?
.json()
.await?;
println!("Sent: {}", res.id);
Ok(())
}