Skip to main content

Rust SDK

The jetemail crate is the official Rust SDK for JetEmail transactional email (MIT license, async with Tokio). Create a transactional API key in the dashboard: OutboundKeys → Add API key. Use that key with the SDK.

Installation

Add to your Cargo.toml:
[dependencies]
jetemail = "0.1"
tokio = { version = "1", features = ["full"] }
Crate on crates.io: jetemail.

Quick start

use jetemail::JetEmail;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = JetEmail::new("your-transactional-api-key");

    let result = client.email().send(
        jetemail::SendEmailOptions::builder()
            .from("Your App <[email protected]>")
            .to("[email protected]")
            .subject("Welcome!")
            .html("<h1>Welcome!</h1>")
            .build(),
    ).await?;

    println!("{}", result.id);
    Ok(())
}
Use a from address on a verified domain (see Getting started).

Constructor

// API key string
let client = JetEmail::new("your-transactional-api-key");

// Or with options
let client = JetEmail::builder()
    .api_key("your-transactional-api-key")
    .base_url("https://api.jetemail.com") // optional
    .build();

client.email().send(options)

Send a single email.
FieldRequiredDescription
fromSender, e.g. "Name <[email protected]>"
toRecipient(s), string or vec (max 50)
subjectSubject line
html*HTML body (need html and/or text)
text*Plain text (need html and/or text)
cc, bcc, reply_toRecipients (max 50 each)
headersCustom headers HashMap
attachmentsAttachments (max 40MB total)
Response shape: SendEmailResponse { id: String, response: String }.

client.batch().send(emails)

Send up to 100 emails in one request. Returns summary (total, successful, failed) and results per message.
let result = client.batch().send(vec![
    SendEmailOptions::builder()
        .from("[email protected]")
        .to("[email protected]")
        .subject("Hello Alice")
        .html("<p>Hi Alice!</p>")
        .build(),
    SendEmailOptions::builder()
        .from("[email protected]")
        .to("[email protected]")
        .subject("Hello Bob")
        .html("<p>Hi Bob!</p>")
        .build(),
]).await?;

Attachments

use jetemail::Attachment;

let result = client.email().send(
    SendEmailOptions::builder()
        .from("[email protected]")
        .to("[email protected]")
        .subject("Invoice")
        .html("<p>Please find your invoice attached.</p>")
        .attachments(vec![
            Attachment::from_path("/path/to/invoice.pdf").await?,
            Attachment::from_content(b"Hello World", "hello.txt"),
        ])
        .build(),
).await?;

Error handling

use jetemail::JetEmailError;

match client.email().send(options).await {
    Ok(result) => println!("Sent: {}", result.id),
    Err(JetEmailError::Api { status_code, message, response }) => {
        eprintln!("{}: {}", status_code, message);
    }
    Err(e) => eprintln!("Error: {}", e),
}
Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.
For additional examples and the full option list, see the crates.io page. REST details: API reference.