The official Rust SDK for the JetEmail email API.
cargo add jetemailOr add it manually to your Cargo.toml:
[dependencies]
jetemail = "0.1"use jetemail::{CreateEmailOptions, JetEmail};
#[tokio::main]
async fn main() -> jetemail::Result<()> {
let client = JetEmail::new("je_your_api_key");
let email = CreateEmailOptions::new(
"you@example.com",
"recipient@example.com",
"Hello from JetEmail!",
)
.with_html("<h1>Hello World!</h1>");
let response = client.emails.send(email).await?;
println!("Email sent! ID: {}", response.id);
Ok(())
}let email = CreateEmailOptions::new(
"you@example.com",
vec!["alice@example.com".into(), "bob@example.com".into()],
"Hello everyone!",
)
.with_html("<p>Hi there!</p>")
.with_cc("cc@example.com")
.with_bcc("bcc@example.com")
.with_reply_to("reply@example.com");use jetemail::Attachment;
let email = CreateEmailOptions::new(
"you@example.com",
"recipient@example.com",
"Email with attachment",
)
.with_html("<p>See attached.</p>")
.with_attachment(Attachment::from_content(b"file contents", "file.txt"))
.with_attachment(Attachment::from_path("./report.pdf")?);Send up to 100 emails in a single API call:
let emails = vec![
CreateEmailOptions::new("you@example.com", "alice@example.com", "Hello Alice!")
.with_html("<p>Hi Alice!</p>"),
CreateEmailOptions::new("you@example.com", "bob@example.com", "Hello Bob!")
.with_html("<p>Hi Bob!</p>"),
];
let response = client.batch.send(emails).await?;let email = CreateEmailOptions::new(
"you@example.com",
"recipient@example.com",
"With custom headers",
)
.with_html("<p>Hello!</p>")
.with_header("X-Custom-Header", "custom-value");// Uses JETEMAIL_API_KEY environment variable
let client = JetEmail::default();Use ConfigBuilder for full control over the client. This lets you override the API base URL (useful for testing against a local or staging server), set a custom user agent, or provide your own reqwest client with custom timeouts or proxy settings.
use jetemail::ConfigBuilder;
let config = ConfigBuilder::new("je_your_api_key")
.base_url("https://staging-api.jetemail.com") // default: https://api.jetemail.com
.user_agent("my-app/1.0")
.client(
reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.unwrap(),
)
.build();
let client = JetEmail::with_config(config);Enable the blocking feature for synchronous usage:
[dependencies]
jetemail = { version = "0.1", features = ["blocking"] }let client = JetEmail::new("je_your_api_key");
let response = client.emails.send(email)?;MIT