Before You Start
Prerequisites:
- OpenClaw installed (15-minute installation guide)
- Gmail or Outlook account (we'll use Gmail in this guide)
- Basic comfort with terminal commands (copy-paste level)
- 10-15 emails in your inbox to test with
What This Agent Does
Your Email Triage Agent will:
- Read unread emails from your Gmail inbox
- Categorize each email into Urgent / Important / Routine / Spam using Claude AI
- Flag urgent messages that need immediate attention (e.g., from your boss, customer complaints, payment failures)
- Draft replies to routine emails (e.g., "When are you available?", "Can you send the invoice?")
- Send you a summary via Telegram with the breakdown and urgent items highlighted
- Run automatically every morning at 8am (scheduled via cron)
Step-by-Step Guide
Create Your Agent Configuration
OpenClaw agents are defined in .openclaw/AGENTS.md. This file tells OpenClaw what agents you have and what they do.
Open your agent configuration:
cd ~/.openclaw
nano AGENTS.md
Add this agent definition:
# Email Triage Agent
**Role:** Inbox manager and email categorization specialist
**Responsibilities:**
- Read all unread emails from Gmail inbox
- Categorize each email as Urgent / Important / Routine / Spam
- Flag urgent messages requiring immediate human attention
- Draft replies to routine emails (save as drafts, don't send)
- Send daily summary via Telegram with breakdown and urgent items
**Skills:**
- gmail_read_messages: Read unread emails
- gmail_create_draft: Create draft replies
- telegram_send_message: Send summary to user
**Triage Rules:**
- URGENT: From boss, customers with "urgent"/"asap", payment/billing issues, server/system alerts
- IMPORTANT: Project updates, meeting invites, client requests, team questions
- ROUTINE: Newsletters, automated notifications, "thanks" replies, low-priority questions
- SPAM: Marketing, cold outreach, suspicious links
**Schedule:** Every day at 8:00 AM (managed via cron)
**Model:** Claude Sonnet (fast + cheap for email processing)
Save and exit: Press Ctrl+O, then Enter, then Ctrl+X
Connect Your Gmail Account
OpenClaw needs permission to read your emails and create drafts. This uses OAuth (no passwords stored).
Run the Gmail authentication flow:
openclaw auth gmail
This will:
- Open your browser to Google's authentication page
- Ask you to select your Gmail account
- Show permissions (read messages, create drafts)
- Save an OAuth refresh token to
~/.openclaw/credentials/gmail.json
Verify connection:
openclaw test-skill gmail_read_messages --limit 5
You should see your 5 most recent unread emails printed to the terminal.
Create the Triage Prompt
Create a reusable prompt that tells Claude how to categorize emails.
Create the prompt file:
mkdir -p ~/.openclaw/prompts
nano ~/.openclaw/prompts/email-triage.txt
Paste this prompt:
You are an email triage specialist. Categorize this email into one of four categories:
**URGENT** - Requires immediate attention (within 1-2 hours)
Examples: Boss/CEO messages, customer complaints, payment failures, system outages, "ASAP" or "urgent" in subject
**IMPORTANT** - Requires attention today
Examples: Project updates, meeting invites, client questions, team collaboration
**ROUTINE** - Can wait 1-3 days
Examples: Newsletters, automated reports, "thanks" replies, low-priority questions
**SPAM** - Marketing, cold outreach, suspicious
Examples: Unsolicited sales emails, promotional content, phishing attempts
For each email, respond with:
1. Category (URGENT/IMPORTANT/ROUTINE/SPAM)
2. One-sentence reason
3. Suggested action (Reply/Archive/Flag/Delete)
4. If category is URGENT or IMPORTANT and email asks a question: draft a short reply
Be strict with URGENT. Only 5-10% of emails should be urgent.
Save and exit.
Create the Agent Script
This script runs the agent: reads emails, triages them, sends summary.
Create the script:
nano ~/.openclaw/scripts/email-triage.sh
Paste this script:
#!/bin/bash
# Email Triage Agent - Runs daily to categorize inbox
# Read the triage prompt
PROMPT=$(cat ~/.openclaw/prompts/email-triage.txt)
# Get unread emails (last 24 hours)
EMAILS=$(openclaw run-skill gmail_read_messages --unread-only --limit 50)
# Run Claude to triage each email
RESULTS=$(echo "$EMAILS" | openclaw chat --agent email-triage --system "$PROMPT")
# Count categories
URGENT=$(echo "$RESULTS" | grep -c "^URGENT")
IMPORTANT=$(echo "$RESULTS" | grep -c "^IMPORTANT")
ROUTINE=$(echo "$RESULTS" | grep -c "^ROUTINE")
SPAM=$(echo "$RESULTS" | grep -c "^SPAM")
# Build summary
SUMMARY="📬 Email Triage Summary ($(date '+%Y-%m-%d %H:%M'))
🔴 URGENT: $URGENT
🟡 IMPORTANT: $IMPORTANT
🟢 ROUTINE: $ROUTINE
⚫ SPAM: $SPAM
$RESULTS"
# Send summary via Telegram
openclaw run-skill telegram_send_message --text "$SUMMARY"
echo "Email triage complete. Summary sent to Telegram."
Make it executable:
chmod +x ~/.openclaw/scripts/email-triage.sh
Test the Agent
Before scheduling, test that it works end-to-end.
Run the script manually:
~/.openclaw/scripts/email-triage.sh
You should see:
- Terminal output showing emails being processed
- Claude's categorization for each email
- A Telegram message with the summary and counts
- No emails found? Make sure you have unread emails in your inbox. Send yourself a test email.
- Telegram not working? Run
openclaw auth telegramfirst to connect your Telegram bot. - Claude errors? Check your Anthropic API key:
openclaw doctor
Schedule Daily Runs
Set up a cron job to run this agent every morning at 8am.
Open your crontab:
crontab -e
Add this line:
# Run email triage agent every day at 8:00 AM
0 8 * * * ~/.openclaw/scripts/email-triage.sh >> ~/.openclaw/logs/email-triage.log 2>&1
Save and exit.
Your agent will now run automatically every morning. Logs are saved to ~/.openclaw/logs/email-triage.log.
What You Just Built
📬 Email Triage Summary (2026-03-15 08:00)
🔴 URGENT: 3
🟡 IMPORTANT: 7
🟢 ROUTINE: 18
⚫ SPAM: 12
=== URGENT ===
1. [Customer Support] Site is down - users can't log in
→ ACTION: Reply immediately, escalate to dev team
2. [CEO] Need Q1 numbers for board meeting today
→ ACTION: Reply with dashboard link
3. [Stripe] Payment failed for invoice #2847
→ ACTION: Update payment method
=== IMPORTANT ===
4. [Project Manager] Design review meeting moved to 2pm
→ DRAFT REPLY: "Thanks for the update. I'll be there."
5. [Client] Can you send the final proposal by Friday?
→ DRAFT REPLY: "Yes, I'll have it to you by Thursday EOD."
[... 5 more IMPORTANT emails ...]
=== ROUTINE & SPAM ===
18 routine emails (newsletters, automated reports)
12 spam emails (cold outreach, promotional)
→ Archived automatically
Customization Ideas
🎯 Make It Smarter
- Learn from your behavior: Track which emails you respond to quickly vs ignore. Update triage rules based on patterns.
- Sender VIP list: Always mark emails from specific people (boss, top clients) as URGENT.
- Keyword triggers: Flag emails containing "invoice", "payment", "urgent", "asap", "deadline".
- Auto-archive spam: Instead of just flagging, automatically archive emails categorized as SPAM (after 7 days of testing).
⚡ Add More Actions
- Auto-send routine replies: For emails like "Thanks!" or "Confirmed", send the draft reply automatically (add
--sendflag). - Create tasks from emails: When an email asks for action, create a Notion task or Todoist item automatically.
- Weekly digest: Send a summary email every Friday with stats (% spam, most common senders, time saved).
- Slack integration: Post urgent emails to a private Slack channel instead of Telegram.
🔄 Multi-Inbox Support
- Multiple Gmail accounts: Run separate triage agents for work@company.com and personal@gmail.com.
- Outlook support: Replace
gmail_read_messageswithoutlook_read_messages(same script structure). - Aggregate summary: Triage 3 inboxes and send one combined Telegram summary.
Time & Cost Breakdown
| Metric | Value |
|---|---|
| Setup time | 30 minutes (one-time) |
| Daily runtime | 30-60 seconds (fully automated) |
| Claude API cost | £0.10-0.30/day (50 emails × Sonnet) |
| Monthly cost | £3-9 (vs £30-70 for Zapier/Make) |
| Time saved per week | 2-3 hours (inbox triage + reply drafting) |
| Annual value | £5,200-7,800 (at £50/hour rate) |
| ROI | 48,000% (pays for itself in 3 days) |
Next Steps
You've just built your first autonomous AI agent. Here's what to do next:
- Let it run for 7 days - Monitor the Telegram summaries and adjust triage rules if needed.
- Build agent #2 - Try the Meeting Notes Agent (covered in Module 1: Security First).
- Learn multi-agent orchestration - The full course teaches you how to run 5-10 agents working together (Module 7).
- Join the community - Share your setup in the OpenClaw Discord and see what others are building.
Troubleshooting
Agent isn't running at 8am
- Check your crontab:
crontab -l - Verify the script path is correct (use absolute paths, not
~) - Check logs:
tail -20 ~/.openclaw/logs/email-triage.log - Test cron is working:
crontab -eand add a test job that runs in 2 minutes
Gmail authentication fails
- Make sure you selected the correct Gmail account during OAuth
- Check that "Less secure app access" is NOT enabled (we use OAuth, not passwords)
- Re-run:
openclaw auth gmail --reset - Verify credentials file exists:
ls -la ~/.openclaw/credentials/gmail.json
Telegram messages not sending
- Authenticate Telegram:
openclaw auth telegram - Test the skill:
openclaw run-skill telegram_send_message --text "Test" - Check bot token is valid:
openclaw doctor
Claude categorizing everything as URGENT
- Strengthen the prompt: Add "Only 5-10% of emails should be URGENT" at the end
- Give examples: Add 2-3 example emails with expected categories to the prompt
- Use temperature: Add
--temperature 0.3to theopenclaw chatcommand (makes Claude more consistent)
Frequently Asked Questions
Is this safe? Can the AI send emails without my permission?
No. By default, OpenClaw uses read-only Gmail access. It can read emails and create drafts, but it cannot send emails unless you explicitly add the --send flag to gmail_create_draft. The script above only creates drafts - you review and send them manually.
What if Claude makes a mistake and marks something urgent as spam?
You'll still see all categorizations in the Telegram summary. Even if something is marked as spam, you can review it. After 7 days of testing and refining your prompt, the accuracy is typically 95%+. You can also add a "confidence score" to the prompt output.
Can I run this on multiple email accounts?
Yes. Create separate agent configurations in AGENTS.md for each account (e.g., email-triage-work and email-triage-personal), authenticate each account separately, and schedule separate cron jobs.
How much does this cost to run?
If you process 50 emails/day with Claude Sonnet: £3-9/month in API costs. Compare to Zapier (£30+/month) or Make.com (£29+/month). OpenClaw is 60-90% cheaper because you only pay for what you use.
What if I want it to auto-reply to some emails?
Modify the script to add --send flag to gmail_create_draft for emails that match certain criteria (e.g., subject contains "meeting confirmed" or sender is a specific person). Start with drafts-only for 14 days to build confidence.