Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

MailKite

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

PyPI

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-dev while the mailkite name is reclaimed — the import is from mailkite import MailKite.

Quickstart

importosfrommailkiteimportMailKitemk=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>",
})

Examples

Runnable examples live in examples/ — send mail, verify webhooks, build an AI email agent, and log users in:

ExampleWhat it shows
examples/01_send_email.pySend an email over a verified domain — the 10-second "it works".
examples/02_receive_webhook.pyReceive inbound email as a webhook — and VERIFY the HMAC signature before trusting it.
examples/03_agent_email_reply.pyAn AI email agent: inbound email → Claude drafts a reply → MailKite sends it, threaded.
examples/04_give_your_agent_an_inbox.pyGive your agent its own email address — MailKite's built-in inbox agent answers mail for…
examples/05_server_login.pyServer-side login + register.

API methods

Every method is documented on its own page under docs/. The full surface:

MethodWhat it does
sendSend a message over a verified domain. Pass templateId (+ optional templateData) to…
sendBatchSend one personalized message per recipient (up to 50) in a single call. Shared fields…
uploadAttachmentUpload a file to MailKite storage and get back a secure, time-limited URL. Reference the…
listTemplatesList your saved email templates (light metadata only — no body). Use getTemplate for the…
listBaseTemplatesList the premade base templates (light metadata). Clone one with createTemplate({ baseId…
getTemplateGet one template (full: subject, html, text, theme). Works for your templates (tpl_…) and…
createTemplateCreate a template. Pass baseId to clone a base template into your own, or provide…
listDomainsList your domains, each with its webhook URL.
createDomainAdd a domain. Returns the domain + DNS records. Paid plans may pass email_provider_id
getDomainGet one domain with DNS records + webhook.
deleteDomainRemove a domain.
verifyDomainCheck DNS and update status.
setWebhookSet or replace the domain's catch-all webhook.
setTrackingWebhookSet or replace the domain's dedicated tracking-event webhook: an HTTPS endpoint that…
deleteTrackingWebhookRemove the domain's tracking-event webhook (engagement events stop).
setWebhookEventsOpt the domain's inbound webhook into engagement events — one webhook, all events. Pass…
deleteWebhookEventsOpt the domain's inbound webhook back out of engagement events (inbound email.received…
deleteWebhookRemove the domain's webhook.
getWebhookSecretGet this domain's webhook signing secret (whsec_…) — the per-route secret used to verify…
testWebhookSend a signed test event to the domain's webhook.
checkDomainAvailabilityCheck whether a domain is available to register, and at what price. Read-only — no charge.
registerDomainRegister (buy) a domain on the customer's behalf; provisions mail DNS and adds it to the…
listRoutesList inbound routing rules.
createRouteCreate a route (match, action, destination).
deleteRouteDelete an inbound routing rule by id. Pair with createRoute to register and tear down a…
agentSend a message to one of your inbox agents and get its reply. Defaults to the account's…
routeRoute a message to one of your registered routes (by routeId or address), running…
listMessagesList stored messages, newest first. Optionally filter with search (matches sender…
getMessageGet a message with deliveries + attachments.
retryDeliveryRe-deliver a stored message to its webhook.
listListsList your contact lists (static, curated broadcast audiences), each with its member count.
createListCreate a contact list. Returns the list with its id (lst_…); add contacts with…
getListGet one contact list with its member count.
updateListRename a contact list.
deleteListDelete a contact list. The list is removed; the contacts themselves are kept.
listListContactsList the contacts that are members of a list, newest first. Optionally page with before
addListContactsAdd contacts (by id, ctr_…) to a list. Returns how many were newly added; contacts…
removeListContactRemove one contact from a list (the contact itself is kept).
listBroadcastsList your broadcasts (one-to-many sends) with status and send stats.
createBroadcastCreate a broadcast draft. from is required; set audience to { type: "all" } or {…
getBroadcastGet one broadcast with its status and recipient summary.
updateBroadcastEdit a draft broadcast (any of from/subject/audience/html/… ). Drafts only.
deleteBroadcastDelete a broadcast draft.
sendBroadcastSend a broadcast now, or pass an ISO 8601 scheduledAt to schedule it. A one-click…
verifyWebhookVerify the x-mailkite-signature header on an inbound webhook delivery. Runs entirely…
replyOkThe acknowledgement body a webhook consumer returns to confirm it processed the event —…
replySpamControl-mode reply a webhook consumer returns to tell MailKite to mark the message as…
replyDropControl-mode reply a webhook consumer returns to tell MailKite to drop (discard) the…
replyBlockSenderControl-mode reply a webhook consumer returns to tell MailKite to block the sender — the…
encryptEncrypt a UTF-8 string to a domain's RSA public key (SPKI/PEM), returning the at-rest…
decryptDecrypt a MailKite at-rest envelope JSON with your RSA private key (PKCS8/PEM), returning…
semanticSearchSemantic search over the MailKite documentation — returns the most relevant doc sections…
getApiKeyGet the account's unrestricted API key (mk_live_…). Read-or-create: the first call mints…
rotateApiKeyRotate the account API key: the old key stops working immediately and a fresh one is…
listScopedKeysList the account's domain-scoped API keys. A scoped key can send and manage only its one…
createScopedKeyCreate a key scoped to one domain. Ideal for per-site installs (e.g. a WordPress plugin)…
deleteScopedKeyRevoke a domain-scoped key. Takes effect immediately.
getUsageCurrent billing-period usage: emails used vs the plan's included bucket (null =…
listSuppressionsList suppressed addresses (unsubscribes, hard bounces, spam complaints, manual). Sends to…
addSuppressionSuppress an address so this account never sends to it again (reason defaults to manual).
removeSuppressionRemove an address from the suppression list (URL-encode the email in the path). Removing…
registerCreate a MailKite account from just an email — no password. Returns the new account's API…
meThe 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):

LibraryRepoDistribution
MailKite for Node.jsmailkite-nodenpm
MailKite for Python (this repo)mailkite-pythonPyPI
MailKite for Rubymailkite-rubyRubyGems
MailKite for Javamailkite-javaMaven Central
MailKite for PHPmailkite-phpPackagist
MailKite for Gomailkite-goGo modules
@mailkite/climailkite-clinpm
@mailkite/mcpmailkite-mcpnpm
@mailkite/clientmailkite-jsnpm
@mailkite/expomailkite-exponpm
MailKiteClientmailkite-swiftSwift Package Manager
dev.mailkite:mailkite-clientmailkite-kotlinMaven Central
mailkite_clientmailkite-flutterpub.dev

Docs & links

Generated from the shared MailKite API contract. © MailKite.

About

Official MailKite Python SDK (mailkite-dev on PyPI). Read-only mirror (sdks/python). Do not edit here.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages