Guide
Why AI Agents Need Email
Email is the internet's universal communication protocol. Every web service uses it for authentication, every business uses it for communication, and every transaction leaves a trail in someone's inbox. For AI agents to operate autonomously in the real world, they need email access — not as a nice-to-have, but as a foundational capability.
The agent bottleneck nobody talks about
AI agents can write code, analyze data, and generate content. But the moment they need to interact with an external service — sign up for an account, verify a domain, receive a webhook notification, or communicate with a human — they hit a wall. That wall is email.
Without email access, an AI agent is isolated. It can reason about the world but cannot participate in it. Email is the bridge between an agent's internal capabilities and the external systems it needs to operate.
1. Authentication and OTP verification
Most web services use email for authentication. When an agent needs to sign up for a service, verify its identity, or recover access, the verification code lands in an inbox. Without the ability to read that inbox, the agent is stuck.
Nylas CLI has a dedicated otp command that extracts verification codes automatically — no regex, no jq, no manual parsing:
# Get the latest OTP code from your inbox (auto-copies to clipboard)
nylas otp get
# Get OTP for a specific account
nylas otp get agent@company.com
# Watch for incoming OTP codes in real-time
nylas otp watch
# Output just the code (for piping to other tools)
nylas otp get --rawThis works for any service that sends email-based verification: two-factor authentication codes, magic links, domain verification tokens, and account confirmation emails. The CLI scans recent messages, identifies OTP patterns, and extracts the code — one command instead of a search-parse-regex pipeline.
2. Two-way communication with humans
Chat interfaces are synchronous — someone has to be online. Email is asynchronous. An AI agent can send a progress report at 3 AM, and the recipient reads it at 9 AM. The agent can receive a reply with new instructions and act on them hours later.
This makes email the natural channel for agent-human collaboration on tasks that span hours or days:
# Agent sends a status update
nylas email send \
--to "manager@company.com" \
--subject "Weekly report: pipeline analysis complete" \
--body "Analysis of 847 leads complete. 23 flagged for review. Full report attached to the shared drive."
# Agent checks for replies with new instructions
nylas email search "weekly report" --from manager@company.com --json
# Agent reads the full thread
nylas email threads show thread_abc123 --jsonUnlike Slack or Discord, email does not require both parties to be on the same platform. The agent can communicate with anyone who has an email address — which is everyone.
3. Immutable audit trails
Every email has headers: timestamps, sender verification (SPF/DKIM/DMARC), message IDs, and threading references. This creates an immutable record of every interaction an agent has. For compliance, debugging, and accountability, email provides a paper trail that chat messages and API logs cannot match.
# Read a message with full headers for audit purposes
nylas email read msg_abc123 --json
# List all sent messages for a compliance export
nylas email list --folder SENT --json | jq '[.[] | {date, to: .to[0].email, subject}]'
# Search for all agent-initiated communications in a date range
nylas email search "*" --from agent@company.com --after 2026-03-01 --jsonWhen you need to answer "what did the agent do and when?", the inbox is the definitive source of truth. Every sent email, every received response, every verification code — all timestamped and authenticated.
4. Multi-threaded conversations
Real-world tasks involve multiple parallel conversations. An agent handling vendor negotiations might be emailing three suppliers simultaneously, each in their own thread. Email threading handles this natively — each conversation maintains its own context without cross-contamination.
# List active threads the agent is managing
nylas email list --json | jq 'group_by(.thread_id) | map({thread: .[0].subject, messages: length}) | sort_by(-.messages)'
# Follow up on a specific thread
nylas email send \
--to "vendor@supplier.com" \
--subject "Re: Q2 pricing proposal" \
--reply-to msg_previous123 \
--body "Following up on the pricing discussion. Can you confirm the volume discount for 10,000 units?"
# Monitor all threads for new replies
nylas email list --unread --jsonAn agent managing multiple threads can context-switch between conversations, maintaining the appropriate tone and history for each one. This is something that flat chat channels struggle with at scale.
Give your agent email access in one command
The Nylas CLI includes a built-in MCP server that gives any compatible AI assistant direct access to email and calendar. No OAuth code, no API keys to manage, no provider-specific integrations.
# Install the Nylas CLI
brew install nylas/nylas-cli/nylas
# Authenticate with your email provider (Gmail, Outlook, etc.)
nylas auth login
# Install MCP for your AI assistant
nylas mcp install --assistant claude-code # Claude Code
nylas mcp install --assistant cursor # Cursor
nylas mcp install --assistant claude-desktop # Claude Desktop
# Or detect and install for all assistants at once
nylas mcp install --allOnce installed, your AI assistant can read, send, search, and manage email directly. No subprocess hacks, no brittle API integrations — just native MCP tools.
Use the CLI directly in agent scripts
For agents built with custom frameworks (LangChain, CrewAI, AutoGen), the CLI works as a subprocess tool. Every command supports --json output for structured parsing:
# List unread messages as structured JSON
nylas email list --unread --json
# Send an email and capture the result
nylas email send --to "user@example.com" --subject "Task complete" --body "Done." --json
# Search with natural language queries
nylas email search "invoice" --from accounting --after 2026-03-01 --json
# Read a specific message by ID
nylas email read msg_abc123 --jsonWorks with every email provider
Unlike direct API integrations that lock you into one provider, Nylas CLI provides a unified interface across all major email providers:
| Provider | Authentication | Setup complexity |
|---|---|---|
| Gmail / Google Workspace | OAuth2 (built in) | One command |
| Outlook / Microsoft 365 | OAuth2 (built in) | One command |
| Exchange Online | OAuth2 (built in) | One command |
| Yahoo Mail | OAuth2 (built in) | One command |
| iCloud Mail | OAuth2 (built in) | One command |
| Any IMAP provider | App password | One command |
The same agent code works regardless of which provider the email account is on. Switch from Gmail to Outlook without changing a single command.
Security considerations
Giving an agent email access requires thought about security boundaries:
- OAuth2 authentication — Nylas CLI never stores email passwords. All provider authentication uses OAuth2 with scoped permissions.
- Send confirmation — MCP-compatible assistants require human confirmation before sending emails, preventing accidental or malicious sends.
- Audit logging — Enable
nylas auditto log every action an agent takes through the CLI, with timestamps and source detection. - Revocable access — Run
nylas auth revokeat any time to immediately cut off agent access to an email account. - Scoped grants — Each authenticated account is a separate grant. An agent with access to one inbox cannot access another without explicit authentication.
Frequently asked questions
Can an AI agent send emails without human approval?
When using MCP (the recommended approach), assistants like Claude require human confirmation before sending. When using the CLI directly in scripts, sends execute immediately — so wrap them in your own approval logic if needed.
What happens if the agent's email access token expires?
Nylas handles token refresh automatically. If a refresh fails (e.g., the user revoked access in their provider settings), the CLI returns a clear error that the agent can handle gracefully.
Can I restrict what an agent can do with email?
Yes. You can scope OAuth permissions during nylas auth login and use audit logging to monitor agent activity. For MCP specifically, you can configure which tools are available to the assistant.
Does this work with self-hosted email servers?
Yes. Any IMAP-compatible server works with Nylas CLI. This includes self-hosted solutions like Dovecot, Zimbra, and hMailServer.
Next steps
- Set up MCP for your AI assistant — step-by-step installation guide
- Email as identity for AI agents — signups, OTP, and account recovery
- Email as memory for AI agents — search and reason over conversation history
- Build an LLM agent with email tools — custom agent framework integration
- Audit AI agent activity — log and monitor everything your agent does