Skip to main content
Email bots connect your AI agents to email — choose AgentMail (zero-config API) or IMAP/SMTP (self-hosted).
The user sends mail to the inbox; the agent reads threads, drafts replies, and sends responses via AgentMail or IMAP/SMTP.

How It Works

Quick Start

Bot("email", agent=agent).run() auto-reconnects on a dropped connection by default and stays supervised until the IMAP poll loop stops — see Auto-reconnect on long-running-bots.

Platform Comparison


Event-Driven Modes (AgentMail)

AgentMailBot supports 4 reception modes. Choose based on your latency and reliability needs.

YAML Configuration

Python API

Webhook Verification

When using mode: webhook, set AGENTMAIL_WEBHOOK_SECRET in production. An unset secret causes all inbound webhooks to be rejected with HTTP 401 (fail-closed).
The AgentMail API token is no longer used as a fallback signing secret. Configure AGENTMAIL_WEBHOOK_SECRET explicitly.
Accepted signature headers: X-AgentMail-Signature, X-Webhook-Signature, X-Signature. For local development without a real AgentMail webhook, set PRAISONAI_INSECURE_WEBHOOKS=true — never in production. See Webhook Verification.

Duplicate protection on retries

AgentMailBot derives one stable AgentMail Idempotency-Key per outbound send and reuses it across every retry (the outbound resilience layer retries up to 3× by default). If a send succeeds on AgentMail but the client times out, the retry is deduplicated at the provider — the recipient gets exactly one email.
Pass your own key when you need deterministic replay across process restarts — for example a key derived from a durable job or webhook id:
The key is forwarded to AgentMail via the Idempotency-Key header. AgentMail honours it for 24 hours. Reuse the same key within that window to guarantee the send is dedup’d.

Inbox Lifecycle Management

AgentMailBot implements the EmailProtocol from the core SDK, enabling programmatic inbox creation:
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:
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


Configuration

Environment Variables

BotConfig Options

send_message Options (AgentMail)


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