Email Agent
Build an agent that monitors your inbox every 15 minutes, classifies emails by category and urgency, drafts personalized replies for routine messages, and sends a Slack digest of items needing your attention.
approval_required: [send_email] by default. It drafts replies as Drafts and routes to your inbox for approval before sending. Never auto-send without reviewing this logic carefully.Agent YAML
# email-agent.yaml
name: email-assistant
description: "Classifies and drafts replies for inbox emails"
llm:
model: gpt-4o-mini
temperature: 0.4
system_prompt: |
You manage email for a busy professional. For each email:
1. Classify: category (sales/support/colleague/newsletter/urgent/spam)
2. Assess urgency: high/medium/low
3. If category is support or colleague AND urgency != spam:
- Draft a professional, personalized reply
- Keep replies to 3-5 sentences unless complexity requires more
4. If urgent: add to escalation list for Slack notification
Return JSON: {category, urgency, draft_reply (or null), escalate_to_slack: bool}
tools:
- imap_read_emails
- gmail_create_draft # Saves draft, does NOT send
- slack_post_message
approval_required:
- gmail_send # Blocked: require human approval before any send
triggers:
- type: cron
schedule: "*/15 * * * *" # Every 15 minutes
run:
agent: email-assistant
input:
folder: INBOX
unread_only: true
max_emails: 50IMAP Tool Configuration
# ~/.openclaw/config.yaml additions
email:
imap_host: imap.gmail.com
imap_port: 993
username: "${EMAIL_ADDRESS}"
password: "${EMAIL_APP_PASSWORD}" # Use app-specific password, not main password
smtp_host: smtp.gmail.com
smtp_port: 587myaccount.google.com/apppasswords. Never store your main Gmail password.Slack Digest for Escalations
# The agent calls slack_post_message for urgent emails
# Configure your Slack webhook:
slack:
webhook_url: "${SLACK_WEBHOOK_URL}"
default_channel: "#email-alerts"The agent will post a digest like:
📧 *Email digest — 3 items need your attention*
🔴 *URGENT* from Alice (CEO): "Q3 board deck review by 5pm"
→ Draft ready in Drafts folder
🟡 From Bob (client): "Invoice question — payment terms"
→ Draft ready in Drafts folder
🔵 Support ticket #1247: Server error on checkout
→ Draft ready, also created Jira ticket BUG-512Running the Email Agent
# Test on last 5 unread emails (dry run)
openclaw run --config email-agent.yaml \
--input '{"folder": "INBOX", "unread_only": true, "max_emails": 5}' \
--dry-run
# Start the scheduled agent
openclaw start --config email-agent.yaml
openclaw status # Check it is runningWhat This Agent Does
This tutorial builds an email management agent that can draft replies, categorize incoming messages, extract action items from email threads, and generate follow-up summaries. The agent does not send email directly — it produces draft content for human review, making it safe to use for professional communication without risk of accidental sends.
Step 1 — Agent Configuration
Create email-agent.yaml:
agent:
name: email-assistant
description: Drafts and processes email content
system_prompt: |
You are a professional email assistant. You help draft replies,
summarize threads, and extract action items from emails.
When drafting replies:
- Match the tone of the original message (formal/informal)
- Be concise and direct — avoid filler phrases
- Clearly state any actions requested or promised
- End with appropriate closing for the relationship
When summarizing threads:
- Identify key decisions made
- List outstanding action items with owners if mentioned
- Note any agreed deadlines
IMPORTANT: You draft content only. Do not claim to send emails.
Always present output as a draft for the user to review.
llm:
model: claude-3-5-sonnet-20241022
temperature: 0.4
max_tokens: 2048
tools:
- name: file_read
enabled: true
- name: file_write
enabled: true
config:
allowed_dirs:
- ./drafts
Step 2 — Draft a Reply
Save an email you want to reply to as email.txt, then run:
openclaw run --config email-agent.yaml --task "Read email.txt and draft a professional reply that:
1. Acknowledges the key points raised
2. Answers the questions asked
3. Proposes a meeting for next Tuesday afternoon if they want to discuss further
Save the draft to drafts/reply.txt"
Step 3 — Batch Process an Inbox
For processing multiple emails, create a processing task:
openclaw run --config email-agent.yaml --task "Read all .txt files in the inbox/ directory. For each:
1. Categorize as: ACTION_REQUIRED, FYI, SPAM, or RESPOND_LATER
2. If ACTION_REQUIRED: extract all action items with owner and due date
3. If ACTION_REQUIRED and from a client: draft a reply acknowledging receipt
Output a summary table and save any draft replies to drafts/"
Step 4 — Thread Summarization
Long email threads are time-consuming to read. Point the agent at a saved thread:
openclaw run --config email-agent.yaml --task "Read thread.txt (a forwarded email chain). Produce:
1. Executive summary (3 sentences max)
2. Timeline of key events/decisions
3. Open questions that haven't been answered
4. My action items (I am Alex Kumar, alex@example.com)"
Step 5 — Weekly Summary Generation
Automate a weekly email digest by combining the agent with scheduled execution:
openclaw run --config email-agent.yaml --task "Read all files in emails/this-week/. Generate a weekly summary including:
total emails processed, key decisions made, commitments given, outstanding items,
and suggested priorities for next week. Format as a brief executive summary
suitable for a Monday morning review." --output reports/weekly-email-summary.md
Troubleshooting
If drafts don't match your communication style, add example emails showing your preferred tone to the system prompt as few-shot examples. If the agent extracts incorrect action items from complex threads, ask it to show its reasoning: add "Explain why you categorized each action item as you did." This chain-of-thought prompting typically improves extraction accuracy significantly.
Tone Matching and Personalization
Effective email drafts match the relationship context. A reply to your CEO should be more formal than a reply to a close colleague, even if both messages are about the same project. Help the agent understand relationship context by including it in the task: "This email is from a client who has been with us for 3 years and communicates in a warm, informal style. Match their tone." The agent reads subtle cues in the original message — greeting style, sentence length, vocabulary formality — and can calibrate its response accordingly when you provide this context.
Build a personal voice library over time. Save examples of your best emails — the ones you're proudest of — to a few-shot examples file that the agent can read for style reference. When drafting a reply, include: "Match my communication style as shown in the examples in my-style-examples.txt." This produces drafts that sound like you rather than generic professional email, reducing the editing you need to do before sending.
Privacy and Confidentiality
Be thoughtful about what email content you feed to an AI agent. Emails often contain confidential business information, personal details, legal discussions, and sensitive personnel matters. Before pointing the agent at your inbox, review your organization's AI use policy and your privacy obligations. For sensitive emails, consider summarizing the key points yourself and asking the agent to draft based on your summary, rather than sharing the raw email content. This gives you the productivity benefit of AI assistance while keeping sensitive details out of the LLM's context.
Building a Reply Template Library
Over time you'll find yourself asking the agent to draft similar types of replies repeatedly: meeting requests, proposal rejections, status update requests, interview scheduling confirmations. Create named task templates for these recurring scenarios in a templates/ directory. Each template specifies the scenario context, the key information the agent should extract from the original email, and the structure of the draft. Running a template is then a one-line command, and the agent handles the customization based on the specific email content.
Email Classification and Routing
Beyond drafting and summarizing, the email agent can classify and route incoming messages. Give it a list of categories relevant to your workflow — customer support, billing inquiry, partnership request, job application, spam — and have it categorize each email and write its classification to a structured output file. A lightweight script then reads this classification file and routes emails to the appropriate folder or person. This inbox triage automation handles the mechanical classification work, letting you focus human attention on the emails that genuinely require judgment and personalized response.
Meeting Request Handling
Meeting requests are one of the most time-consuming categories of email to process manually. The agent can read a meeting request, extract the proposed time slots, check your stated availability (provide it in the task), select the best slot, and draft a confirmation reply with calendar invite details already included. For recurring meeting types — weekly syncs, quarterly reviews, client check-ins — create task templates pre-populated with your standard meeting format preferences, duration, and video call link. Processing routine meeting scheduling becomes a seconds-long task rather than a context-switching interruption in your workflow.