Skip to main content

Python SDK for mails-agent — email capabilities for AI agents

Project description

mails-agent

Python SDK for mails0.com -- email capabilities for AI agents.

Install

pip install mails-agent

Quick start

from mails_agent import MailsClient

client = MailsClient(
    api_url="https://mails-worker.your-domain.com",
    token="your-api-token",
    mailbox="agent@mails0.com",
)

# Send an email
result = client.send(
    to="user@example.com",
    subject="Hello from my agent",
    text="This email was sent by an AI agent.",
)
print(f"Sent: {result.id}")

# Check inbox
emails = client.get_inbox(limit=5)
for email in emails:
    print(f"{email.from_address}: {email.subject}")

# Wait for a verification code (long-polls up to 30s)
code = client.wait_for_code(timeout=30)
if code:
    print(f"Got code: {code.code}")

API reference

MailsClient(api_url, token, mailbox, *, timeout=60.0)

Create a synchronous client. Supports use as a context manager:

with MailsClient(api_url, token, mailbox) as client:
    emails = client.get_inbox()

send(to, subject, *, text=None, html=None, reply_to=None, attachments=None) -> SendResult

Send an email. to can be a single address or a list.

result = client.send(
    to=["alice@example.com", "bob@example.com"],
    subject="Team update",
    html="<h1>Update</h1><p>Everything is on track.</p>",
    reply_to="noreply@mails0.com",
)

Attachments are passed as a list of dicts:

client.send(
    to="user@example.com",
    subject="Report",
    text="See attached.",
    attachments=[{
        "filename": "report.pdf",
        "content": base64_encoded_string,
        "content_type": "application/pdf",
    }],
)

get_inbox(*, limit=20, offset=0, direction=None, query=None) -> list[Email]

Fetch emails from the inbox with optional filtering.

# Get latest 10 inbound emails
emails = client.get_inbox(limit=10, direction="inbound")

# Search for emails containing "invoice"
emails = client.get_inbox(query="invoice")

search(query, *, limit=20, direction=None) -> list[Email]

Search emails by query string. Convenience wrapper around get_inbox.

results = client.search("verification code", limit=5)

get_email(email_id) -> Email

Fetch a single email by its ID. Raises NotFoundError if it does not exist.

email = client.get_email("abc-123")
print(email.body_text)

wait_for_code(*, timeout=30) -> VerificationCode | None

Long-poll the server for a verification code. Returns None if no code arrives within the timeout.

code = client.wait_for_code(timeout=60)
if code:
    print(f"Code: {code.code}, From: {code.from_address}")

delete_email(email_id) -> bool

Delete an email. Returns True if deleted, False if not found.

deleted = client.delete_email("abc-123")

Async usage

All methods are available as async via AsyncMailsClient:

import asyncio
from mails_agent import AsyncMailsClient

async def main():
    async with AsyncMailsClient(
        api_url="https://mails-worker.your-domain.com",
        token="your-api-token",
        mailbox="agent@mails0.com",
    ) as client:
        # Send
        result = await client.send("user@example.com", "Hello", text="Hi!")

        # Inbox
        emails = await client.get_inbox()

        # Wait for code
        code = await client.wait_for_code(timeout=30)

asyncio.run(main())

Data models

Email

Field Type Description
id str Unique email ID
mailbox str Mailbox address
from_address str Sender email
from_name str Sender display name
subject str Subject line
direction str "inbound" or "outbound"
status str "received", "sent", "failed", "queued"
received_at str ISO 8601 timestamp
has_attachments bool Whether email has attachments
attachment_count int Number of attachments
body_text str Plain text body
body_html str HTML body
code str | None Extracted verification code, if any

SendResult

Field Type Description
id str Message ID
provider str Send provider used
provider_id str | None Provider-specific ID

VerificationCode

Field Type Description
code str The verification code
from_address str Sender of the code email
subject str Subject of the code email

Exceptions

Exception When
MailsError Base class for all SDK errors
AuthError 401 or 403 response
NotFoundError 404 response
ApiError Any other non-2xx response (has .status_code)

License

MIT

Project details


Download files

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

Source Distribution

mails_agent-1.4.0b1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

mails_agent-1.4.0b1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mails_agent-1.4.0b1.tar.gz.

File metadata

  • Download URL: mails_agent-1.4.0b1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mails_agent-1.4.0b1.tar.gz
Algorithm Hash digest
SHA256 6dd579348598b04937d3ba3b9d847b90b99106e4e4f7222b1b2369c472f6d23a
MD5 5781fdf9e982abda4c90615b77cbbee2
BLAKE2b-256 1a1d334029a014369bc6fb6a42c417b1f29c79e7e521d6b9d4950b2ce0206d73

See more details on using hashes here.

File details

Details for the file mails_agent-1.4.0b1-py3-none-any.whl.

File metadata

  • Download URL: mails_agent-1.4.0b1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mails_agent-1.4.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 e21b7b4471c1278e5b9afac862b18c6b42f458f97056bea1bd2a796db16dcfd4
MD5 c4451955b7476c700c71bc2097608e6f
BLAKE2b-256 b227eaa53ed7f294d48361cc12bd75b1f1f6155f32558c975bf9404874bed526

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