Phase 8 / Ep 38: AgentMail —— Enabling Agents to Send and Receive Emails
🎯 Learning Objective: Configure the AgentMail MCP Server and implement email automation.
1. What is AgentMail?
AgentMail is an MCP (Model Context Protocol) Server, providing AI Agents with dedicated email addresses. Agents can send and receive emails just like humans—eliminating the need for manual forwarding.
graph LR
Agent["🤖 Agent"] -->|"MCP Protocol"| AM["📧 AgentMail\nMCP Server"]
AM -->|"SMTP/IMAP"| Email["📬 Email System"]
Email --> Inbox["Inbox"]
Email --> Sent["Sent"]2. Installation and Configuration
# Install AgentMail
npx clawhub install agentmail
# Configure (requires AgentMail API Key)
openclaw config set mcp.agentmail.apiKey "am_xxx"
openclaw config set mcp.agentmail.email "[email protected]"
Alternatively, configure in openclaw.json:
{
"mcp": {
"servers": {
"agentmail": {
"command": "npx",
"args": ["agentmail-mcp-server"],
"env": {
"AGENTMAIL_API_KEY": "${AGENTMAIL_API_KEY}"
}
}
}
}
}
3. Email Operation Capabilities
After installation, the Agent gains the following tools:
| Tool | Function | Example |
|---|---|---|
send_email |
Send email | Send weekly report to [email protected] |
read_emails |
Read inbox | Check for new emails |
reply_email |
Reply to email | Reply to customer inquiry |
search_emails |
Search emails | Search for emails containing "invoice" |
4. Practical Scenarios
Scenario One: Automatic Daily Report Sending
sequenceDiagram
actor User as 🧑 You
participant TG as 📱 Telegram
participant Agent as 🤖 Agent
participant AM as 📧 AgentMail
participant Boss as 📬 [email protected]
User->>TG: "Send today's work daily report to my boss"
TG->>Agent: Instruction received
Agent->>Agent: Organize today's diary from memory/
Agent->>Agent: Draft email body
Agent->>AM: send_email(to: [email protected],\nsubject: "4/6 Work Daily Report",\nbody: "...")
AM->>Boss: SMTP Send
AM->>Agent: ✅ Sent successfully
Agent->>TG: "✅ Daily report sent to [email protected]"Scenario Two: Reading Emails to Extract Tasks
You: "Check the inbox, are there any new tasks?"
Agent (internal): read_emails(unread: true)
→ Found 3 new emails
Agent: "You have 3 new emails:
1. 📧 Alice (10:30) - Request to review PR #42
2. 📧 Bob (11:15) - Inquiry about API documentation link
3. 📧 Newsletter (12:00) - OpenClaw v3.1 Release Announcement
Which one do you need me to reply to?"
Scenario Three: Cron Automatic Reply
openclaw cron add "Email Check" --schedule "*/30 * * * *" \
--action "Check inbox, generate reply drafts for new emails not tagged as 'newsletter', and notify me via Telegram for review"
5. Security Controls
{
"mcp": {
"agentmail": {
"restrictions": {
"allowedRecipients": ["*@company.com", "[email protected]"],
"maxEmailsPerDay": 50,
"requireApproval": true
}
}
}
}
| Security Policy | Description |
|---|---|
| Recipient Whitelist | Can only send to specified domains |
| Daily Limit | Prevents Agent from spamming |
| Manual Approval | Requests confirmation via Telegram before sending |
Next Episode Preview: Ep 39, A Tour of the MCP Ecosystem—Beyond AgentMail, there are four essential MCP Servers: Browser, Database, GitHub, and Calendar.