| Crates.io | sentd |
| lib.rs | sentd |
| version | 1.0.0 |
| created_at | 2026-01-25 15:30:50.811009+00 |
| updated_at | 2026-01-25 15:30:50.811009+00 |
| description | Official Rust SDK for the SENTD Email API |
| homepage | https://sentd.io |
| repository | https://github.com/sentd-it/sentd-rust |
| max_upload_size | |
| id | 2068969 |
| size | 85,602 |
Official Rust client for the SENTD Email API.
Add this to your Cargo.toml:
[dependencies]
sentd = "1.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use sentd::{Sentd, SendEmailRequest};
#[tokio::main]
async fn main() -> Result<(), sentd::Error> {
// Create a new client
let client = Sentd::new("your_api_key");
// Send an email
let result = client.emails().send(SendEmailRequest {
from: "hello@yourdomain.com".to_string(),
to: vec!["user@example.com".to_string()],
subject: "Welcome!".to_string(),
html: Some("<h1>Hello World</h1>".to_string()),
..Default::default()
}).await?;
println!("Email sent! ID: {}", result.data.id);
Ok(())
}
// Send an email
let result = client.emails().send(SendEmailRequest {
from: "hello@yourdomain.com".to_string(),
to: vec!["user@example.com".to_string()],
subject: "Hello".to_string(),
html: Some("<h1>World</h1>".to_string()),
..Default::default()
}).await?;
// List emails
let emails = client.emails().list(Some(ListEmailsParams {
limit: Some(10),
status: Some("delivered".to_string()),
..Default::default()
})).await?;
// Get an email
let email = client.emails().get("email_id").await?;
// Cancel a scheduled email
client.emails().cancel("email_id").await?;
// Resend a failed email
client.emails().resend("email_id").await?;
use sentd::{SendBatchRequest, BatchEmail};
use std::collections::HashMap;
let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("Alice"));
let result = client.batch().send(SendBatchRequest {
emails: vec![
BatchEmail {
to: "user1@example.com".to_string(),
data: Some(data),
..Default::default()
},
],
from: Some("hello@yourdomain.com".to_string()),
subject: Some("Newsletter".to_string()),
html: Some("<h1>Hello {{name}}</h1>".to_string()),
..Default::default()
}).await?;
use sentd::CreateTemplateRequest;
// Create a template
let template = client.templates().create(CreateTemplateRequest {
name: "Welcome Email".to_string(),
subject_template: "Welcome, {{name}}!".to_string(),
html_template: "<h1>Hello {{name}}</h1>".to_string(),
..Default::default()
}).await?;
// List templates
let templates = client.templates().list().await?;
// Preview a template
let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("John"));
let preview = client.templates().preview("template_id", data).await?;
// Add a domain
let domain = client.domains().add("yourdomain.com").await?;
// List domains
let domains = client.domains().list().await?;
// Verify a domain
let result = client.domains().verify("domain_id").await?;
use sentd::CreateWebhookRequest;
// Create a webhook
let webhook = client.webhooks().create(CreateWebhookRequest {
url: "https://yourdomain.com/webhooks".to_string(),
events: vec!["email.delivered".to_string(), "email.bounced".to_string()],
active: Some(true),
}).await?;
// Test a webhook
let result = client.webhooks().test("webhook_id").await?;
use sentd::analytics::AnalyticsParams;
// Get analytics
let analytics = client.analytics().get(Some(AnalyticsParams {
days: Some(30),
group_by: Some("day".to_string()),
})).await?;
// Export as CSV
let csv = client.analytics().export_csv(Some(30)).await?;
// Custom base URL
let client = Sentd::with_base_url("your_api_key", "https://custom.api.sentd.io");
use sentd::Error;
match client.emails().send(request).await {
Ok(result) => println!("Sent: {}", result.data.id),
Err(Error::Authentication(msg)) => eprintln!("Invalid API key: {}", msg),
Err(Error::RateLimit(msg)) => eprintln!("Rate limited: {}", msg),
Err(Error::Validation(msg)) => eprintln!("Validation error: {}", msg),
Err(Error::NotFound(msg)) => eprintln!("Not found: {}", msg),
Err(e) => eprintln!("Error: {}", e),
}
MIT License - see LICENSE for details.