Rust SDK
Send email with Rust
Install the official Parcel Wing Rust SDK, configure a server-side API key, and send your first transactional email.
Requirements
- Rust 1.75 or newer.
- A Parcel Wing API key stored as
PARCELWING_API_KEY. - A verified sending domain for your
fromaddress.
Install the SDK
The official Rust SDK is published as parcelwing.
Terminal
cargo add parcelwingcargo add tokio --features macros,rt-multi-thread
Send your first email
Create a Client and call client.emails().send(...).await.
src/main.rs
use parcelwing::{Client, EmailSendRequest};#[tokio::main]async fn main() -> Result<(), parcelwing::Error> {let client = Client::new(std::env::var("PARCELWING_API_KEY").unwrap())?;let emails = client.emails().send(EmailSendRequest::new("Acme <[email protected]>",).subject("Hello from Parcel Wing").html("<strong>It works!</strong>").text("It works."),).await?;println!("{}", emails[0].id);Ok(())}
Configuration
Use ClientOptions to set a custom base URL or timeout for local testing.
src/client.rs
use std::time::Duration;use parcelwing::{Client, ClientOptions};let client = Client::with_options(ClientOptions {api_key: std::env::var("PARCELWING_API_KEY").unwrap(),base_url: Some(std::env::var("PARCELWING_BASE_URL").unwrap_or_else(|_| "https://parcelwing.com".to_string())),timeout: Some(Duration::from_secs(30)),default_headers: Default::default(),})?;
Send to multiple recipients
Pass a vector of recipient addresses to queue one message per recipient.
src/bulk.rs
let emails = client.emails().send(EmailSendRequest::new("Acme <[email protected]>",vec!["[email protected]", "[email protected]"],).subject("Hello from Parcel Wing").text("It works."),).await?;
Use a template
Use template_alias and template_param for reusable lifecycle messages.
src/templates.rs
let emails = client.emails().send(EmailSendRequest::new("Acme <[email protected]>",).template_alias("welcome").template_param("first_name", "Ada").template_param("plan", "Launch"),).await?;
Handle errors
API and network failures return parcelwing::Error.
src/errors.rs
match client.emails().send(request).await {Ok(emails) => println!("Queued: {emails:#?}"),Err(parcelwing::Error::Api(api_error)) => {eprintln!("Parcel Wing API error: {} ({:?})", api_error.message, api_error.code);}Err(error) => eprintln!("Request failed: {error}"),}
Framework guides
Axum
Use Parcel Wing from a Axum application with server-side API key handling.
Actix Web
Use Parcel Wing from a Actix Web application with server-side API key handling.
Rocket
Use Parcel Wing from a Rocket application with server-side API key handling.
Warp
Use Parcel Wing from a Warp application with server-side API key handling.
Poem
Use Parcel Wing from a Poem application with server-side API key handling.
Tide
Use Parcel Wing from a Tide application with server-side API key handling.