MailKite Rust SDK
The official MailKite SDK for Rust — inbound email → webhook,
sending, templates, contact lists, broadcasts, at-rest encryption, and webhook signature
verification. One low-level request plus one thin method per API endpoint; bodies and
responses are plain [serde_json::Value].
[]
= "0.13"
Quickstart
use Client;
use json;
Authentication — API key or OAuth
The credential is always a Bearer token, so an OAuth access token works anywhere an API key does. Rule of thumb: server-to-server code → API key; anything that renders on a public URL → OAuth (so each user acts as themselves, not through a shared key).
use Client;
// Server-to-server: a static API key (mk_live_…).
let mk = new;
// OAuth: a static access token — same constructor, any Bearer credential.
let mk = new;
// …or, because OAuth access tokens are short-lived, a get_token callback the SDK
// calls before each request so it always sends a fresh one (you refresh it):
let mk = new_with_token;
// Point at a custom base URL (self-hosted / testing):
let mk = new_with_base_url;
Get an OAuth token from MailKite's authorization server (mcp.mailkite.dev, OAuth 2.1 +
PKCE, dynamic client registration).
Receiving email (webhooks)
Verify the signature before trusting an inbound event — a local HMAC-SHA256 check, no network call. Pass the raw, unparsed request body.
if mk.verify_webhook
At-rest encryption
Hybrid RSA-OAEP (SHA-256) + AES-256-GCM. The envelope is byte-compatible with every other MailKite SDK and MailKite's own WebCrypto, so you can encrypt in one language and decrypt in another.
let envelope = mk.encrypt?; // -> compact JSON string
let plaintext = mk.decrypt?;
Uploading attachments
Get a secure, time-limited URL instead of base64-inlining large files on every send. Provide
the file one of four ways (url, bytes, path, or base64 content):
use AttachmentUpload;
let up = mk.upload_attachment?;
// then reference up["url"] as a send() attachment { filename, url }
License
MIT