All solutions
Solutions

Send Email from a Python AI Agent

One requests.post() and your Python agent has a working email address. No SMTP, no OAuth.

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. Send as hello, the agent every new workspace gets at signup, 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']}"}

requests.post(f"{API}/messages", headers=HEADERS, json={
    "agent": "hello",
    "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. The free tier covers 3,000 emails and 3,000 inbound replies a month with no card; Pro is $20 a month for 50,000 emails.

Need to handle inbound messages too? See Email API with Webhooks for Inbound Messages — Python AI Agents for Flask and FastAPI handler patterns, HMAC signature verification, and the full bidirectional receive-then-reply flow.

Frequently asked questions

Is there a Python SDK?
Yes: the Python SDK is live on PyPI as mailsai (pip install mailsai) and wraps this same REST surface. The API is also plain HTTPS + JSON, so the requests snippet on this page is a complete integration on its own. A TypeScript SDK (@mailsai/sdk) and an MCP server are on npm.
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

Give your first agent an inbox

Free covers 3,000 emails and 3,000 inbound replies a month, with no card. Upgrade when your agents get busy.

Get your API key