Solutions
Send Email from a Python AI Agent
To send email from a Python AI agent, skip SMTP entirely: create an agent over the REST API, then POST the message as JSON. Your agent gets a real address it owns, replies come back as parsed webhooks, and there is no mail server, OAuth consent screen, or MIME assembly anywhere in your code.
The whole integration is one HTTPS call
No smtplib, no app passwords, no email.mime. Create an agent once, then send with the standard library of your choice:
import os, requests
API = "https://api.mails.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MAILS_API_KEY']}"}
# one-time: create the agent (it gets its own address)
requests.post(f"{API}/agents", headers=HEADERS, json={"name": "sarah"})
# send
requests.post(f"{API}/messages", headers=HEADERS, json={
"agent": "sarah",
"to": "user@example.com",
"subject": "Your report is ready",
"body_text": "Attached below — reply with questions, I read every message.",
})Why not just use SMTP or a transactional API?
SMTP from a script means managing credentials, deliverability, and identity yourself — and most transactional APIs assume a human application, not an autonomous sender. Here the agent is the first-class object: it owns an address, builds its own sending reputation, and its inbound mail is parsed and scanned for prompt injection before your code ever reads it. Sending is $0.001 per message with no monthly minimum.
Frequently asked questions
Is there a Python SDK?
The API is plain HTTPS + JSON, so the requests snippet on this page is the whole integration. A TypeScript SDK (@mailsai/sdk) and an MCP server are on npm today; the Python SDK is coming next and will wrap this same REST surface.
Does this work with LangGraph, CrewAI, or Pydantic AI?
Yes — anything that can make an HTTPS request can send. For framework-specific setup, the integrations section has dedicated guides, including LangGraph and Pydantic AI.
How does my agent receive replies in Python?
Register a webhook and each reply arrives as parsed JSON (sender, subject, clean text body, thread id) — an ordinary POST handler in Flask or FastAPI is enough. You can also poll GET /v1/events.
Explore the product
Built for agents.
Self-serve in minutes.
The API is live and self-serve. Drop ~6 lines into your agent and ship.
$ npm install @mailsai/sdk