1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// 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)
}
}