MailKite for Python
Email for every product you ship — receive email as a webhook, send over a verified domain, give an AI agent its own inbox.
The official MailKite library for Python.
Docs · Library guide · mailkite.dev · AI agents
Read-only mirror. This repo is a generated, release-time mirror of the MailKite monorepo (the private source of truth) — development doesn't happen here. Install from PyPI and open issues against the MailKite docs.
Install
pip install mailkite-dev
Published as
mailkite-devwhile themailkitename is reclaimed — the import isfrom mailkite import MailKite.
Quickstart
import os
from mailkite import MailKite
mk = MailKite(os.environ["MAILKITE_API_KEY"])
res = mk.send({
"from": "hello@myapp.ai",
"to": "ada@example.com",
"subject": "Your invoice #1042",
"html": "<p>Thanks! Receipt attached.</p>",
})
Templates from your repo
Besides templateId (a saved template, rendered server-side), a body can come from a local .html, .htm or .txt file:
res = mk.send({
"from": "hello@myapp.ai",
"to": "ada@example.com",
"subject": "Welcome aboard",
"templateFile": "./emails/welcome.html",
"templateData": {"name": "Ada"},
})
The file is read by the SDK and sent as html/text — the API never sees templateFile. A welcome.txt sitting next to welcome.html becomes the plaintext part, and {{merge_tags}} in the file are still filled from templateData server-side. Works on sendBatch, createTemplate and createBroadcast too.
Examples
Runnable examples live in examples/ — send mail, verify webhooks, build an AI email agent, and log users in:
| Example | What it shows |
|---|---|
examples/01_send_email.py |
Send an email over a verified domain — the 10-second "it works". |
examples/02_receive_webhook.py |
Receive inbound email as a webhook — and VERIFY the HMAC signature before trusting it. |
examples/03_agent_email_reply.py |
An AI email agent: inbound email → Claude drafts a reply → MailKite sends it, threaded. |
examples/04_give_your_agent_an_inbox.py |
Give your agent its own email address — MailKite's built-in inbox agent answers mail for… |
examples/05_server_login.py |
Server-side login + register. |
API methods
Every method is documented on its own page under docs/. The full surface:
| Method | What it does |
|---|---|
send |
Send a message over a verified domain. Pass templateId (+ optional templateData) to… |
sendBatch |
Send one personalized message per recipient (up to 50) in a single call. Shared fields… |
sendEvent |
Record one application-level fact about a user — user.created, trial.expiring… |
listEvents |
List recorded events, newest first — the surface for confirming a POST landed and for… |
listEventNames |
List the distinct event names this account works with, so an editor can offer them… |
listSequences |
List your sequences, newest first, each with live enrollment counts. Archived sequences… |
createSequence |
Create a sequence: a declared input shape, the steps a contact walks over time, and zero… |
getSequence |
Get one sequence with its definition and live enrollment counts. |
updateSequence |
Edit a sequence. Changing the STEPS bumps its version and contacts already in flight keep… |
deleteSequence |
Delete a sequence and retire every contact still walking it. The response reports how… |
listTriggers |
List the triggers attached to a sequence — the doors into it. |
createTrigger |
Attach a trigger: when this event arrives, enroll the contact it is about. Attaching… |
updateTrigger |
Edit a trigger, or toggle enabled to switch the door off without deleting it. Either… |
deleteTrigger |
Detach a trigger. Stops future enrollments through that door and nothing else. |
startSequence |
Start a sequence for one contact, directly — when your code already knows WHICH sequence… |
stopSequence |
Stop whatever is chasing someone. Pass the cancelKey you set when starting — so you… |
listEnrollments |
List who is in a sequence and where each of them is. Filter with status. |
getEnrollment |
Get one enrollment — which sequence, which step, and what happens next. |
listEnrollmentRuns |
Every step this enrollment has executed, with the outcome and the reason for it. This is… |
cancelEnrollment |
Cancel one specific run by its enrollment id — the per-row action when you are looking at… |
uploadAttachment |
Upload a file to MailKite storage and get back a secure, time-limited URL. Reference the… |
listTemplates |
List your saved email templates (light metadata only — no body). Use getTemplate for the… |
listBaseTemplates |
List the premade base templates (light metadata). Clone one with createTemplate({ baseId… |
getTemplate |
Get one template (full: subject, html, text, theme). Works for your templates (tpl_…) and… |
createTemplate |
Create a template. Pass baseId to clone a base template into your own, or provide… |
listDomains |
List your domains, each with its webhook URL. |
createDomain |
Add a domain. Returns the domain + DNS records. Paid plans may pass email_provider_id… |
suggestSubdomain |
Suggest a free, currently-unclaimed subdomain label to prefill the input with, plus the… |
checkSubdomain |
Check whether a free subdomain label can be claimed. Read-only and cheap — call it as the… |
claimSubdomain |
Claim a free MailKite subdomain — a <label>.<base> host on a zone we run (call… |
getDomain |
Get one domain with DNS records + webhook. |
deleteDomain |
Remove a domain. |
verifyDomain |
Check DNS and update status. |
setWebhook |
Set or replace the domain's catch-all webhook. |
setTrackingWebhook |
Set or replace the domain's dedicated tracking-event webhook: an HTTPS endpoint that… |
deleteTrackingWebhook |
Remove the domain's tracking-event webhook (engagement events stop). |
setWebhookEvents |
Opt the domain's inbound webhook into engagement events — one webhook, all events. Pass… |
deleteWebhookEvents |
Opt the domain's inbound webhook back out of engagement events (inbound email.received… |
deleteWebhook |
Remove the domain's webhook. |
getWebhookSecret |
Get this domain's webhook signing secret (whsec_…) — the per-route secret used to verify… |
testWebhook |
Send a signed test event to the domain's webhook. |
checkDomainAvailability |
Check whether a domain is available to register, and at what price. Read-only — no charge. |
registerDomain |
Register (buy) a domain on the customer's behalf; provisions mail DNS and adds it to the… |
listRoutes |
List inbound routing rules. |
createRoute |
Create a route (match, action, destination). |
deleteRoute |
Delete an inbound routing rule by id. Pair with createRoute to register and tear down a… |
agent |
Send a message to one of your inbox agents and get its reply. Defaults to the account's… |
route |
Route a message to one of your registered routes (by routeId or address), running… |
listMessages |
List stored messages, newest first. Optionally filter with search (matches sender… |
getMessage |
Get a message with deliveries + attachments. |
retryDelivery |
Re-deliver a stored message to its webhook. |
retryDeliveries |
Replay a whole selection of webhook deliveries in one call — the bulk form of… |
listDeliveryAttempts |
Every captured attempt for one delivery, newest first: the request headers and payload we… |
deliverToRoute |
POST stored messages to one webhook route — including messages that arrived BEFORE the… |
listRouteCandidates |
Stored inbound messages this route could be asked to deliver, newest first — the preview… |
createRealtimeToken |
Mint a short-lived, single-use token that authorises one Realtime API connection. For… |
listLists |
List your contact lists (static, curated broadcast audiences), each with its member count. |
createList |
Create a contact list. Returns the list with its id (lst_…); add contacts with… |
getList |
Get one contact list with its member count. |
updateList |
Rename a contact list. |
deleteList |
Delete a contact list. The list is removed; the contacts themselves are kept. |
listListContacts |
List the contacts that are members of a list, newest first. Optionally page with before… |
addListContacts |
Add contacts (by id, ctr_…) to a list. Returns how many were newly added; contacts… |
removeListContact |
Remove one contact from a list (the contact itself is kept). |
listBroadcasts |
List your broadcasts (one-to-many sends) with status and send stats. |
createBroadcast |
Create a broadcast draft. from is required; set audience to { type: "all" } or {… |
getBroadcast |
Get one broadcast with its status and recipient summary. |
updateBroadcast |
Edit a draft broadcast (any of from/subject/audience/html/… ). Drafts only. |
deleteBroadcast |
Delete a broadcast draft. |
sendBroadcast |
Send a broadcast now, or pass an ISO 8601 scheduledAt to schedule it. A one-click… |
verifyWebhook |
Verify the x-mailkite-signature header on an inbound webhook delivery. Runs entirely… |
replyOk |
The acknowledgement body a webhook consumer returns to confirm it processed the event —… |
replySpam |
Control-mode reply a webhook consumer returns to tell MailKite to mark the message as… |
replyDrop |
Control-mode reply a webhook consumer returns to tell MailKite to drop (discard) the… |
replyBlockSender |
Control-mode reply a webhook consumer returns to tell MailKite to block the sender — the… |
encrypt |
Encrypt a UTF-8 string to a domain's RSA public key (SPKI/PEM), returning the at-rest… |
decrypt |
Decrypt a MailKite at-rest envelope JSON with your RSA private key (PKCS8/PEM), returning… |
semanticSearch |
Semantic search over the MailKite documentation — returns the most relevant doc sections… |
registerOauthClient |
Register an OAuth client for this installation (RFC 7591 dynamic client registration) —… |
exchangeOauthToken |
Exchange an authorization code for an access token (or rotate a refresh token) — step 3… |
getApiKey |
Get the account's unrestricted API key (mk_live_…). Read-or-create: the first call mints… |
rotateApiKey |
Rotate the account API key: the old key stops working immediately and a fresh one is… |
listScopedKeys |
List the account's domain-scoped API keys. A scoped key can send and manage only its one… |
createScopedKey |
Create a key scoped to one domain. Ideal for per-site installs (e.g. a WordPress plugin)… |
deleteScopedKey |
Revoke a domain-scoped key. Takes effect immediately. |
listAppPasswords |
List the account's app passwords. Each one opens a mailbox over IMAP and/or the mailbox… |
createAppPassword |
Create an app password for one domain and address pattern. Hand it to a mail client or an… |
updateAppPassword |
Change what an app password covers — its label, address pattern, or protocols. The domain… |
rotateAppPassword |
Replace an app password's secret, keeping its scope. The old secret stops authenticating… |
deleteAppPassword |
Revoke an app password. Takes effect immediately — any IMAP session or API call using it… |
listMailboxMessages |
List a mailbox's messages, newest first. Authenticated with an app password granting… |
getMailboxMessageRaw |
Fetch one message's raw RFC822 bytes from a mailbox. Same app password auth as the list. |
setMailboxMessageFlags |
Replace a message's IMAP flags (e.g. mark it Seen). Flags set here are the same ones an… |
getUsage |
Current billing-period usage: emails used vs the plan's included bucket (null =… |
listSuppressions |
List suppressed addresses (unsubscribes, hard bounces, spam complaints, manual). Sends to… |
addSuppression |
Suppress an address so this account never sends to it again (reason defaults to manual). |
removeSuppression |
Remove an address from the suppression list (URL-encode the email in the path). Removing… |
register |
Create a MailKite account from just an email — no password. Returns the new account's API… |
me |
The account behind this credential: email, whether it is verified (sending is blocked… |
Use it from an AI agent — MCP + Agent connectors
MailKite speaks the Model Context Protocol: every API method is a tool your AI assistant (Claude, Cursor, …) can call — send mail, manage domains, search the docs, and give an agent its own inbox. Full guide: https://mailkite.dev/docs/ai-agents.
Hosted (recommended) — one-click OAuth, no key to copy:
claude mcp add --transport http mailkite https://mcp.mailkite.dev/mcp
In Claude Code you can also install the plugin:
/plugin marketplace add mailkite/claude-code
/plugin install mailkite@mailkite
Any chat/UI agent: "Add the MCP server at https://mcp.mailkite.dev/mcp and authenticate in the browser when prompted."
Local (static key, offline / CI):
{ "mcpServers": { "mailkite": { "command": "npx", "args": ["-y", "@mailkite/mcp"], "env": { "MAILKITE_API_KEY": "mk_live_…" } } } }
Give an agent its own inbox. Route inbound mail to a built-in inbox agent (the agent route action) and it answers, files, or escalates on its own — see https://mailkite.dev/docs/ai-agents.
All MailKite libraries
Same contract, every language — pick the one for your stack (full list: https://mailkite.dev/docs/libraries):
| Library | Repo | Distribution |
|---|---|---|
| MailKite for Node.js | mailkite-node |
npm |
| MailKite for Python (this repo) | mailkite-python |
PyPI |
| MailKite for Ruby | mailkite-ruby |
RubyGems |
| MailKite for Java | mailkite-java |
Maven Central |
| MailKite for PHP | mailkite-php |
Packagist |
| MailKite for Go | mailkite-go |
Go modules |
| @mailkite/cli | mailkite-cli |
npm |
| @mailkite/mcp | mailkite-mcp |
npm |
| @mailkite/client | mailkite-js |
npm |
| @mailkite/expo | mailkite-expo |
npm |
| MailKiteClient | mailkite-swift |
Swift Package Manager |
| dev.mailkite:mailkite-client | mailkite-kotlin |
Maven Central |
| mailkite_client | mailkite-flutter |
pub.dev |
Docs & links
- 📚 Documentation: https://mailkite.dev/docs
- 📦 This library's guide: https://mailkite.dev/docs/libraries
- 🤖 AI agents (MCP + inbox agents): https://mailkite.dev/docs/ai-agents
- 🌐 Website: https://mailkite.dev
- 🧭 All libraries: https://mailkite.dev/docs/libraries
Generated from the shared MailKite API contract. © MailKite.
Metadata
Release files for mailkite-dev 0.20.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mailkite_dev-0.20.0.tar.gz | 29.4 kB | Without provenance | Details for mailkite_dev-0.20.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mailkite_dev-0.20.0-py3-none-any.whl | Python 3 | none | any | Details for mailkite_dev-0.20.0-py3-none-any.whl |
Total release size: 49.3 kB
Release files / mailkite_dev-0.20.0.tar.gz
| Download URL | mailkite_dev-0.20.0.tar.gz |
|---|---|
| Size | 29.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c3f0c09ea7e824238acbe923f7d13bcff7c6180897a9c4f3fd69c6d41f10a9c
|
|
BLAKE2b-256 checksum How to use checksums |
ecbe2756e869f084bbe272b63c694a821081a839225c68cf37a7d3afd7b8651a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mailkite_dev-0.20.0-py3-none-any.whl
| Download URL | mailkite_dev-0.20.0-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53cb558230fa4e31805eb2e1c9ef9f69e2bbf7eb1e1bbd199eb9fffe5f0f8ff5
|
|
BLAKE2b-256 checksum How to use checksums |
10d6b8af4aee2b2b9fded44b7393e4dd0b35af448b51802b3143894de6b04538
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for mailkite-dev 0.20.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.