unosend

Crates.iounosend
lib.rsunosend
version1.0.0
created_at2025-12-27 19:06:57.851757+00
updated_at2025-12-27 19:06:57.851757+00
descriptionOfficial Rust SDK for Unosend - Email API for developers
homepagehttps://unosend.co
repositoryhttps://github.com/unosend/unosend-rust
max_upload_size
id2007686
size60,055
Venkat  (bittucreator)

documentation

https://docs.rs/unosend

README

Unosend Rust SDK

The official Rust SDK for Unosend - Email API for developers.

Installation

Add to your Cargo.toml:

[dependencies]
unosend = "1.0"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }

Requirements

  • Rust 1.70 or higher
  • Tokio runtime

Quick Start

use unosend::{Unosend, SendEmailRequest, EmailRecipient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Unosend::new("un_your_api_key");

    let response = client.emails().send(SendEmailRequest {
        from: "hello@yourdomain.com".into(),
        to: "user@example.com".into(),
        subject: "Welcome!".into(),
        html: Some("<h1>Hello!</h1><p>Welcome to our platform.</p>".into()),
        ..Default::default()
    }).await?;

    println!("Email sent: {}", response.id);
    Ok(())
}

Priority Sending

Use priority to control email delivery speed:

let response = client.emails().send(SendEmailRequest {
    from: "noreply@yourdomain.com".into(),
    to: "user@example.com".into(),
    subject: "Your verification code: 847293".into(),
    html: Some("<p>Your OTP code is: <strong>847293</strong></p>".into()),
    priority: Some("high".into()), // "high", "normal", or "low"
    ..Default::default()
}).await?;

Using Templates

use std::collections::HashMap;

let mut template_data = HashMap::new();
template_data.insert("first_name".into(), serde_json::json!("John"));
template_data.insert("company_name".into(), serde_json::json!("Acme Inc"));

let response = client.emails().send(SendEmailRequest {
    from: "hello@yourdomain.com".into(),
    to: "user@example.com".into(),
    subject: "Welcome!".into(),
    template_id: Some("550e8400-e29b-41d4-a716-446655440000".into()),
    template_data: Some(template_data),
    ..Default::default()
}).await?;

Scheduled Sending

use chrono::{Utc, Duration};

let tomorrow = Utc::now() + Duration::days(1);

let response = client.emails().send(SendEmailRequest {
    from: "hello@yourdomain.com".into(),
    to: "user@example.com".into(),
    subject: "Good morning!".into(),
    html: Some("<p>This email was scheduled.</p>".into()),
    scheduled_for: Some(tomorrow.to_rfc3339()),
    ..Default::default()
}).await?;

Send to Multiple Recipients

let response = client.emails().send(SendEmailRequest {
    from: "hello@yourdomain.com".into(),
    to: vec!["user1@example.com".into(), "user2@example.com".into()].into(),
    subject: "Team Update".into(),
    html: Some("<h1>Important Update</h1>".into()),
    cc: Some(vec!["manager@example.com".into()]),
    bcc: Some(vec!["archive@example.com".into()]),
    reply_to: Some("support@yourdomain.com".into()),
    ..Default::default()
}).await?;

Working with Domains

// Add a domain
let domain = client.domains().create("yourdomain.com").await?;
println!("Domain added: {}", domain.id);

// List all domains
let domains = client.domains().list().await?;
for d in domains.data {
    println!("{} - {}", d.name, d.status);
}

// Verify domain
let domain = client.domains().verify(&domain.id).await?;

// Delete domain
client.domains().delete(&domain.id).await?;

Working with Audiences & Contacts

use unosend::CreateContactRequest;

// Create an audience
let audience = client.audiences().create("Newsletter Subscribers").await?;

// Add a contact
let contact = client.contacts().create(CreateContactRequest {
    audience_id: audience.id.clone(),
    email: "user@example.com".into(),
    first_name: Some("John".into()),
    last_name: Some("Doe".into()),
    unsubscribed: None,
}).await?;

// List contacts
let contacts = client.contacts().list(&audience.id).await?;

Error Handling

use unosend::UnosendError;

match client.emails().send(request).await {
    Ok(response) => println!("Sent: {}", response.id),
    Err(UnosendError::Api { message, status_code }) => {
        eprintln!("API Error: {} (status: {})", message, status_code);
    }
    Err(UnosendError::Network(e)) => {
        eprintln!("Network error: {}", e);
    }
    Err(e) => eprintln!("Error: {}", e),
}

License

MIT

Commit count: 0

cargo fmt