Skip to main content
Email bots connect your AI agents to email. Choose between IMAP/SMTP (self-hosted) or AgentMail (zero-config API with event-driven modes).

Quick Start


Platform Comparison

FeatureEmailBot (IMAP/SMTP)AgentMailBot (API)
SetupEmail credentials + IMAP/SMTP configAPI key only
Email AddressYour existing addressAuto-generated (@agentmail.to)
Custom Domains✅ Any provider✅ Via create_inbox(domain=...)
Inbox Lifecycle❌ Manualcreate_inbox() / delete_inbox()
Event-Driven Modes❌ Poll onlypoll, ws, webhook, hybrid
Fastest Latency10-30s (poll interval)~250ms (WebSocket push)
DependenciesNone (stdlib)pip install agentmail
Best ForCorporate/existing emailNew projects, multi-inbox, real-time

Event-Driven Modes (AgentMail)

AgentMailBot supports 4 reception modes. Choose based on your latency and reliability needs.
ModeTriggerLatencyUse Case
pollTimer (default)10-30sBackwards compat, simple
wsAgentMail WebSocket push~250msDev, single-bot, self-hosted
webhookAgentMail HTTP POST~350msProduction, horizontal scale
hybridWS primary + 60s poll fallback~250msRecommended — fast + reliable

YAML Configuration

```yaml
# Poll (default — omit mode)
channels:
  agentmail:
    token: ${AGENTMAIL_API_KEY}
```
<!-- slide -->
```yaml
# WebSocket (simplest event-driven)
channels:
  agentmail:
    token: ${AGENTMAIL_API_KEY}
    mode: ws
```
<!-- slide -->
```yaml
# Webhook (production, scalable)
channels:
  agentmail:
    token: ${AGENTMAIL_API_KEY}
    mode: webhook
    webhook_url: https://my-server.com
    webhook_port: 8080
```
<!-- slide -->
```yaml
# Hybrid (recommended)
channels:
  agentmail:
    token: ${AGENTMAIL_API_KEY}
    mode: hybrid
```

Python API

```python
# Poll (default)
bot = AgentMailBot(token="am_...", agent=agent)
await bot.start()  # polls every 10s
```
<!-- slide -->
```python
# WebSocket — sub-second
bot = AgentMailBot(token="am_...", agent=agent, mode="ws")
await bot.start()  # opens WS, receives events instantly
```
<!-- slide -->
```python
# Hybrid — recommended
bot = AgentMailBot(token="am_...", agent=agent, mode="hybrid")
await bot.start()  # WS primary + 60s poll fallback
```
<!-- slide -->
```python
# Webhook — production
bot = AgentMailBot(
    token="am_...", agent=agent,
    mode="webhook", webhook_port=9090
)
await bot.start()  # starts HTTP server, registers webhook
```

Inbox Lifecycle Management

AgentMailBot implements the EmailProtocol from the core SDK, enabling programmatic inbox creation:
# Create a new inbox
inbox = await bot.create_inbox(domain="mycompany.com")
print(inbox["email_address"])  # support-abc@mycompany.com

# List all inboxes
inboxes = await bot.list_inboxes()

# Delete an inbox
await bot.delete_inbox(inbox["id"])
Use isinstance(bot, EmailProtocol) to check if a bot supports inbox lifecycle management at runtime.

Using as Agent Tools

Don’t need a full bot? Use email as one-shot agent tools — auto-detects backend from env vars:
from praisonaiagents import Agent
from praisonaiagents.tools.email_tools import (
    send_email, list_emails, read_email, reply_email,
    search_emails, archive_email, draft_email
)

agent = Agent(
    name="Mailer",
    instructions="Send, read, and manage emails",
    tools=[send_email, list_emails, read_email, reply_email, search_emails, archive_email, draft_email]
)

agent.start("Search my inbox for emails from Bob and archive the old ones")
export AGENTMAIL_API_KEY="am_..."
export AGENTMAIL_INBOX_ID="you@agentmail.to"
# Same code, uses AgentMail API
Or use the email profile: tools=resolve_profiles("email") — includes send, list, read, reply.

Shared Features

Both EmailBot and AgentMailBot share these capabilities:
  • Auto-Reply Prevention: Detects Auto-Submitted headers and common bot addresses to prevent infinite loops.
  • Blocked Sender Filtering: Configurable via BotConfig.blocked_users.
  • Email Address Extraction: Parses "Name <email>" format consistently.
  • Session Isolation: Per-sender AgentState for independent conversations.
  • Command Handling: Subject-based commands (e.g., START:, STOP:).
  • Thread Correlation: In-Reply-To and References headers maintained.

Capabilities Matrix

CapabilityEmailBot (IMAP)AgentMailBot
Receive email (poll)
Receive email (WebSocket)
Receive email (webhook)
Receive email (hybrid)
Send / reply email
Sub-second latency✅ (~250ms)
Auto-reconnect✅ (1s→60s backoff)
No missed messages❌ (poll gaps)✅ (hybrid mode)
Webhook server + health check✅ (GET /health)
YAML mode: config
Graceful shutdown (all modes)⚠️ Poll only✅ All modes
Async client✅ (lazy AsyncAgentMail)

Configuration

Environment Variables

VariablePlatformDefaultDescription
AGENTMAIL_API_KEYAgentMailAgentMail API key
AGENTMAIL_INBOX_IDAgentMailExisting inbox to connect to
AGENTMAIL_DOMAINAgentMailCustom domain for new inboxes
EMAIL_ADDRESSIMAP/SMTPBot email address
EMAIL_APP_PASSWORDIMAP/SMTPApp Password (recommended)
EMAIL_IMAP_SERVERIMAP/SMTPimap.gmail.comIMAP server
EMAIL_SMTP_SERVERIMAP/SMTPsmtp.gmail.comSMTP server
EMAIL_POLL_INTERVALBoth60 / 10Seconds between checks

BotConfig Options

OptionTypeDefaultDescription
modestr"poll"Reception mode: poll, ws, webhook, hybrid
webhook_urlstrNonePublic URL for webhook registration
webhook_pathstr"/webhook"Webhook endpoint path
webhook_portint8080Webhook server port
polling_intervalfloat1.0Seconds between polls

Best Practices

mode: hybrid gives sub-second latency via WebSocket with a 60-second poll fallback to catch any missed messages. Best of both worlds.
Never use your main account password. Generate a platform-specific App Password for the bot.
Use BotConfig.blocked_users to exclude noreply addresses or known marketing domains.
Need separate inboxes per customer? Use AgentMailBot.create_inbox() to provision on demand.

Messaging Bots

All supported messaging platforms

Bot Commands

Register custom commands