mailkite 0.13.0

Official MailKite SDK for Rust — inbound email → webhook, sending, templates, broadcasts, at-rest encryption, and webhook signature verification.
Documentation
// AUTO-GENERATED from sdks/spec/api.json by sdks/gen/methods-codegen.mjs — DO NOT EDIT.
use serde_json::Value;
use crate::{enc, page_query, Client, Error};

impl Client {
    /// Send a message over a verified domain. Pass `templateId` (+ optional `templateData`) to send from a saved or base template.
    pub fn send(&self, message: Value) -> Result<Value, Error> {
        self.request("POST", &"/v1/send".to_string(), Some(message))
    }

    /// List your saved email templates (light metadata only — no body). Use getTemplate for the full template.
    pub fn list_templates(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/templates".to_string(), None)
    }

    /// List the premade base templates (light metadata). Clone one with createTemplate({ baseId }) or send from it directly via send({ templateId }).
    pub fn list_base_templates(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/templates/base".to_string(), None)
    }

    /// Get one template (full: subject, html, text, theme). Works for your templates (tpl_…) and base templates (base_…).
    pub fn get_template(&self, id: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/templates/{}", enc(id)), None)
    }

    /// Create a template. Pass `baseId` to clone a base template into your own, or provide name/subject/html/text/theme directly.
    pub fn create_template(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/templates".to_string(), Some(body))
    }

    /// List your domains, each with its webhook URL.
    pub fn list_domains(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/domains".to_string(), None)
    }

    /// Add a domain. Returns the domain + DNS records.
    pub fn create_domain(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/domains".to_string(), Some(body))
    }

    /// Get one domain with DNS records + webhook.
    pub fn get_domain(&self, id: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/domains/{}", enc(id)), None)
    }

    /// Remove a domain.
    pub fn delete_domain(&self, id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/domains/{}", enc(id)), None)
    }

    /// Check DNS and update status.
    pub fn verify_domain(&self, id: &str) -> Result<Value, Error> {
        self.request("POST", &format!("/api/domains/{}/verify", enc(id)), None)
    }

    /// Set or replace the domain's catch-all webhook.
    pub fn set_webhook(&self, id: &str, body: Value) -> Result<Value, Error> {
        self.request("PUT", &format!("/api/domains/{}/webhook", enc(id)), Some(body))
    }

    /// Remove the domain's webhook.
    pub fn delete_webhook(&self, id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/domains/{}/webhook", enc(id)), None)
    }

    /// Send a signed test event to the domain's webhook.
    pub fn test_webhook(&self, id: &str) -> Result<Value, Error> {
        self.request("POST", &format!("/api/domains/{}/webhook/test", enc(id)), None)
    }

    /// Check whether a domain is available to register, and at what price. Read-only — no charge.
    pub fn check_domain_availability(&self, domain: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/domains/register/check?domain={}", enc(domain)), None)
    }

    /// Register (buy) a domain on the customer's behalf; provisions mail DNS and adds it to the account in one call. Charges the registrar.
    pub fn register_domain(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/domains/register".to_string(), Some(body))
    }

    /// List inbound routing rules.
    pub fn list_routes(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/routes".to_string(), None)
    }

    /// Create a route (match, action, destination).
    pub fn create_route(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/routes".to_string(), Some(body))
    }

    /// Delete an inbound routing rule by id. Pair with createRoute to register and tear down a webhook destination — e.g. an automation platform subscribing on enable and cleaning up on disable.
    pub fn delete_route(&self, id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/routes/{}", enc(id)), None)
    }

    /// Send a message to one of your inbox agents and get its reply. Defaults to the account's default agent; pass `routeId` or `address` to target a specific agent, or `model` to override the model. This is separate from inbound routing — it does not match or override routes.
    pub fn agent(&self, message: Value) -> Result<Value, Error> {
        self.request("POST", &"/v1/agent".to_string(), Some(message))
    }

    /// Route a message to one of your registered routes (by `routeId` or `address`), running that route's action — agent, webhook, or forward. The route must already exist on your account; arbitrary destinations are not allowed.
    pub fn route(&self, message: Value) -> Result<Value, Error> {
        self.request("POST", &"/v1/route".to_string(), Some(message))
    }

    /// List stored messages, newest first. Optionally filter with `search` (matches sender, recipient, or subject) and page with `before` (a `received_at` cursor) and `limit`; omit all for the default newest 100. Response is a bare array — paginate by passing the last row's `received_at` as the next `before`.
    pub fn list_messages(&self, before: Option<i64>, limit: Option<i64>, search: Option<&str>) -> Result<Value, Error> {
        self.request("GET", &format!("/api/messages{}", page_query(before, limit, search)), None)
    }

    /// Get a message with deliveries + attachments.
    pub fn get_message(&self, id: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/messages/{}", enc(id)), None)
    }

    /// Re-deliver a stored message to its webhook.
    pub fn retry_delivery(&self, id: &str) -> Result<Value, Error> {
        self.request("POST", &format!("/api/deliveries/{}/retry", enc(id)), None)
    }

    /// List your contact lists (static, curated broadcast audiences), each with its member count.
    pub fn list_lists(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/lists".to_string(), None)
    }

    /// Create a contact list. Returns the list with its id (lst_…); add contacts with addListContacts.
    pub fn create_list(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/lists".to_string(), Some(body))
    }

    /// Get one contact list with its member count.
    pub fn get_list(&self, id: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/lists/{}", enc(id)), None)
    }

    /// Rename a contact list.
    pub fn update_list(&self, id: &str, body: Value) -> Result<Value, Error> {
        self.request("PATCH", &format!("/api/lists/{}", enc(id)), Some(body))
    }

    /// Delete a contact list. The list is removed; the contacts themselves are kept.
    pub fn delete_list(&self, id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/lists/{}", enc(id)), None)
    }

    /// List the contacts that are members of a list, newest first. Optionally page with `before` (a `last_seen_at`/`created_at` cursor) and `limit`. Response is a bare array — paginate by passing the last row's `last_seen_at` (or `created_at`) as the next `before`.
    pub fn list_list_contacts(&self, id: &str, before: Option<i64>, limit: Option<i64>, search: Option<&str>) -> Result<Value, Error> {
        self.request("GET", &format!("{}{}", format!("/api/lists/{}/contacts", enc(id)), page_query(before, limit, search)), None)
    }

    /// Add contacts (by id, ctr_…) to a list. Returns how many were newly added; contacts already on the list are ignored.
    pub fn add_list_contacts(&self, id: &str, body: Value) -> Result<Value, Error> {
        self.request("POST", &format!("/api/lists/{}/contacts", enc(id)), Some(body))
    }

    /// Remove one contact from a list (the contact itself is kept).
    pub fn remove_list_contact(&self, id: &str, contact_id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/lists/{}/contacts/{}", enc(id), enc(contact_id)), None)
    }

    /// List your broadcasts (one-to-many sends) with status and send stats.
    pub fn list_broadcasts(&self, ) -> Result<Value, Error> {
        self.request("GET", &"/api/broadcasts".to_string(), None)
    }

    /// Create a broadcast draft. `from` is required; set `audience` to { type: "all" } or { type: "list", id: "lst_…" }. Returns the broadcast with its id (bct_…). Send it with sendBroadcast.
    pub fn create_broadcast(&self, body: Value) -> Result<Value, Error> {
        self.request("POST", &"/api/broadcasts".to_string(), Some(body))
    }

    /// Get one broadcast with its status and recipient summary.
    pub fn get_broadcast(&self, id: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/api/broadcasts/{}", enc(id)), None)
    }

    /// Edit a draft broadcast (any of from/subject/audience/html/… ). Drafts only.
    pub fn update_broadcast(&self, id: &str, body: Value) -> Result<Value, Error> {
        self.request("PATCH", &format!("/api/broadcasts/{}", enc(id)), Some(body))
    }

    /// Delete a broadcast draft.
    pub fn delete_broadcast(&self, id: &str) -> Result<Value, Error> {
        self.request("DELETE", &format!("/api/broadcasts/{}", enc(id)), None)
    }

    /// Send a broadcast now, or pass an ISO 8601 `scheduledAt` to schedule it. A one-click unsubscribe is always added. Returns the status and resolved audience count.
    pub fn send_broadcast(&self, id: &str, body: Value) -> Result<Value, Error> {
        self.request("POST", &format!("/api/broadcasts/{}/send", enc(id)), Some(body))
    }

    /// Semantic search over the MailKite documentation — returns the most relevant doc sections for a natural-language query (hybrid vector + keyword search over https://mailkite.dev/docs). Public; no authentication required.
    pub fn semantic_search(&self, query: &str) -> Result<Value, Error> {
        self.request("GET", &format!("/v1/docs/search?query={}", enc(query)), None)
    }

}