Quick Start
- AgentMail (Recommended)
- IMAP/SMTP (Self-Hosted)
Platform Comparison
| Feature | EmailBot (IMAP/SMTP) | AgentMailBot (API) |
|---|---|---|
| Setup | Email credentials + IMAP/SMTP config | API key only |
| Email Address | Your existing address | Auto-generated (@agentmail.to) |
| Custom Domains | ✅ Any provider | ✅ Via create_inbox(domain=...) |
| Inbox Lifecycle | ❌ Manual | ✅ create_inbox() / delete_inbox() |
| Event-Driven Modes | ❌ Poll only | ✅ poll, ws, webhook, hybrid |
| Fastest Latency | 10-30s (poll interval) | ~250ms (WebSocket push) |
| Dependencies | None (stdlib) | pip install agentmail |
| Best For | Corporate/existing email | New projects, multi-inbox, real-time |
Event-Driven Modes (AgentMail)
AgentMailBot supports 4 reception modes. Choose based on your latency and reliability needs.| Mode | Trigger | Latency | Use Case |
|---|---|---|---|
poll | Timer (default) | 10-30s | Backwards compat, simple |
ws | AgentMail WebSocket push | ~250ms | Dev, single-bot, self-hosted |
webhook | AgentMail HTTP POST | ~350ms | Production, horizontal scale |
hybrid | WS primary + 60s poll fallback | ~250ms | Recommended — fast + reliable |
YAML Configuration
Python API
Inbox Lifecycle Management
AgentMailBot implements theEmailProtocol from the core SDK, enabling programmatic inbox creation:
Using as Agent Tools
Don’t need a full bot? Use email as one-shot agent tools — auto-detects backend from env vars:- AgentMail Backend
- Gmail / Outlook Backend
Shared Features
BothEmailBot and AgentMailBot share these capabilities:
- Auto-Reply Prevention: Detects
Auto-Submittedheaders 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
AgentStatefor independent conversations. - Command Handling: Subject-based commands (e.g.,
START:,STOP:). - Thread Correlation:
In-Reply-ToandReferencesheaders maintained.
Capabilities Matrix
| Capability | EmailBot (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
| Variable | Platform | Default | Description |
|---|---|---|---|
AGENTMAIL_API_KEY | AgentMail | — | AgentMail API key |
AGENTMAIL_INBOX_ID | AgentMail | — | Existing inbox to connect to |
AGENTMAIL_DOMAIN | AgentMail | — | Custom domain for new inboxes |
EMAIL_ADDRESS | IMAP/SMTP | — | Bot email address |
EMAIL_APP_PASSWORD | IMAP/SMTP | — | App Password (recommended) |
EMAIL_IMAP_SERVER | IMAP/SMTP | imap.gmail.com | IMAP server |
EMAIL_SMTP_SERVER | IMAP/SMTP | smtp.gmail.com | SMTP server |
EMAIL_POLL_INTERVAL | Both | 60 / 10 | Seconds between checks |
BotConfig Options
| Option | Type | Default | Description |
|---|---|---|---|
mode | str | "poll" | Reception mode: poll, ws, webhook, hybrid |
webhook_url | str | None | Public URL for webhook registration |
webhook_path | str | "/webhook" | Webhook endpoint path |
webhook_port | int | 8080 | Webhook server port |
polling_interval | float | 1.0 | Seconds between polls |
Best Practices
Use Hybrid Mode for Production
Use Hybrid Mode for Production
mode: hybrid gives sub-second latency via WebSocket with a 60-second poll fallback to catch any missed messages. Best of both worlds.Use Dedicated App Passwords
Use Dedicated App Passwords
Never use your main account password. Generate a platform-specific App Password for the bot.
Configure Blocked Senders
Configure Blocked Senders
Use
BotConfig.blocked_users to exclude noreply addresses or known marketing domains.Use AgentMail for Multi-Tenant
Use AgentMail for Multi-Tenant
Need separate inboxes per customer? Use
AgentMailBot.create_inbox() to provision on demand.Related
Messaging Bots
All supported messaging platforms
Bot Commands
Register custom commands

