Skip to main content

mailsai

Email API for AI agents — Python SDK.

Per-agent email addresses on your domain, per-agent reputation, and prompt-injection scanning on every inbound. Your agent reads the reply and decides what to say — intent + entity extraction is opt-in.

pip install mailsai

Quick start

Create the agent once (this mints its inbox address), then send from it. Skipping the create step is the most common first-run error — agent("sarah") only references an agent, it does not create one, so sending returns 404 agent_not_found.

from mailsai import Client, agent

# Reads MAILS_API_KEY from env (or pass api_key=... explicitly)
client = Client()

# One-time setup: create the agent. It gets sarah@<your-workspace>.mails.ai
client.create_agent("sarah")

sarah = agent("sarah")

# mails.ai is transactional-only: mail the recipient asked for. Cold outreach and bulk
# marketing are refused with 422 cold_email_prohibited — that is deliberate, and it is
# what keeps the sending reputation clean for everyone on the platform.
sarah.send(
    to="you@example.com",
    subject="Your verification code is 481902",
    body="Your verification code is 481902. It expires in 15 minutes.",
)

@sarah.on_reply
def handle(reply):
    # Always present — the delivery + security + identity layer:
    # reply["injection_score"]   -> 0.02   # six-category prompt-injection scan
    # reply["sender_reputation"] -> 0.91   # per-agent reputation
    #
    # Present only when classification is enabled (opt-in, +$0.003/inbound):
    # reply["intent"]            -> "schedule_demo" | "ask_question" | …
    # reply["entities"]          -> {"date": "...", "time": "..."}
    # reply["urgency"]           -> 0.8
    #
    # Your agent reads the reply and decides what to send next.
    print(reply["injection_score"], reply["sender_reputation"])

sarah.start_listening()  # blocks; opens SSE stream and dispatches replies

For non-blocking, pass blocking=False to start_listening() — it returns a daemon thread.

Lower-level client

from mailsai import create_client

c = create_client()  # reads MAILS_API_KEY

# Send via any agent
c.send("sarah", to="lead@example.com", subject="Demo", body_text="…")

# Resources
threads = c.list_threads(agent_id="agent_abc123")
usage = c.usage()
rep = c.get_reputation(agent_id="agent_abc123")

# Drafts
draft = c.create_draft(agent="sarah", to="lead@example.com", subject="Demo", body_text="…")
c.send_draft(draft["id"])

Webhook verification

from mailsai import verify_webhook

# In your webhook handler:
event = verify_webhook(
    body=request.body.decode(),
    signature=request.headers["X-Mails-Signature"],
    secret=os.environ["MAILS_WEBHOOK_SECRET"],
)
if event is None:
    return Response(status=400)
# event is the verified inbound event dict

Errors

from mailsai import MailsError

try:
    sarah.send(to="blocked@example.com", subject="…", body="…")
except MailsError as e:
    print(e.type, e.code, e.message, e.status, e.request_id)

Configuration

Param / env var Default
api_key / MAILS_API_KEY (required)
base_url / MAILS_BASE_URL https://api.mails.ai

Documentation

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailsai-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailsai-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file mailsai-0.1.1.tar.gz.

File metadata

  • Download URL: mailsai-0.1.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.2

File hashes

Hashes for mailsai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d07bd25d977d6504caa18a71e14bcdf777f1f4dd5f8eeb24baf753797c44e70e
MD5 c0561252a8612822491a620396d0ba33
BLAKE2b-256 3977f3bc4bb4a342d0b2ae842c82ca281f5785607ce788f94654f099c614797b

See more details on using hashes here.

File details

Details for the file mailsai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mailsai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.2

File hashes

Hashes for mailsai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31ff4e1e54d85e3b873e94ee51c497a440d2e025a348106644e5e5e25d508cc7
MD5 991de6bde760d3dd8050140faddb2568
BLAKE2b-256 eea0e04153bbfa499dec6cc5bf4ebcb9216291432780096c0d31fd49029598d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page