Skip to main content

Rust SDK

The jetemail crate is the official Rust SDK for JetEmail transactional email (MIT license, async via reqwest on Tokio, with an optional blocking feature for synchronous use). Create a transactional API key in the dashboard: Outbound → Keys → Add API key. Use that key with the SDK.

Installation

Or add to your Cargo.toml:
TLS uses native-tls by default; enable the rustls feature instead with jetemail = { version = "0.1", default-features = false, features = ["rustls"] }. Crate on crates.io: jetemail. Source on GitHub: jetemail/jetemail-rust.

Quick start

Use a from address on a verified domain (see Getting started).

Creating a client

JetEmail is Clone and exposes two services as public fields:

client.emails.send(email)

Send a single email. Build the request with CreateEmailOptions::new(from, to, subject) and chain with_* methods for optional fields. All fields are also public on the struct.

Responses

send returns jetemail::Result<CreateEmailResponse>, where CreateEmailResponse { id: String }.

client.batch.send(emails)

Send up to 100 emails in one request as a Vec<CreateEmailOptions>. The SDK rejects an empty vec or more than 100 emails client-side (returned as Error::JetEmail with status_code: 0). Returns BatchEmailResponse { data: Vec<CreateEmailResponse> }.
The REST batch endpoint returns summary and results, not data, so the current crate version fails to parse a successful batch response and returns Error::Parse. Until the crate is updated, send emails individually with client.emails.send or call the batch endpoint directly.

Attachments

Attachment::from_content(bytes, filename) base64-encodes in-memory bytes; Attachment::from_path(path) reads a file synchronously (returning std::io::Result<Attachment>) and uses the file name as the filename. Attachments are sent as { "filename": ..., "data": <base64> }.
jetemail::Error does not implement From<std::io::Error>, so using ? on from_path requires a function that returns Result<_, Box<dyn std::error::Error>> (or map the error yourself).

Error handling

All methods return jetemail::Result<T> (an alias for Result<T, jetemail::Error>). The Error enum has three variants:
Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.

Blocking usage

Enable the blocking feature to use the same API synchronously (no Tokio required). JetEmail::with_client and ConfigBuilder::client then take a reqwest::blocking::Client.

For additional examples, see the README on GitHub. REST details: API reference.