Email Assistant
Agent

Build an AI agent that summarizes email threads, drafts professional replies, and sorts your inbox by priority. Built with OpenCode in under 20 minutes.

Need to set up OpenCode first?

This guide assumes you have OpenCode and a free model provider configured. If you haven't set that up yet:

  1. Install OpenCode: curl -fsSL https://opencode.ai/install | bash
  2. Get a free API key from OpenRouter (no credit card needed)
  3. Or follow the full setup guide for detailed steps

What You'll Build

By the end of this guide, you'll have a command-line email assistant that can:

  • Read email text from files or pasted input (plain text or .eml format)
  • Summarize threads into bullet points with key action items
  • Draft professional replies matching the tone of the original message
  • Sort by priority -- flag urgent emails, separate FYIs from action-required
  • Batch process a folder of emails and generate a daily digest

This agent works with text input -- you paste or pipe email content into it. It does not connect to your actual email account (that would require OAuth and API credentials). Think of it as your local email processing tool.

Privacy first
Since this runs locally and processes text you provide, your emails never leave your machine. This is a major advantage over cloud-based email AI tools. If you use Zoho Mail or another provider, you can export emails as text files and process them locally.
1

Create Your Project

Set up a project folder with an AGENTS.md context file.

mkdir -p ~/projects/email-agent
cd ~/projects/email-agent
mkdir emails
mkdir -p ~/projects/email-agent
cd ~/projects/email-agent
mkdir emails

Create a sample email file so you have something to test with:

cat > emails/sample1.txt << 'EOF'
From: sarah@example.com
To: you@example.com
Subject: Q3 Budget Review - Action Needed by Friday
Date: 2026-04-01

Hi,

I've attached the Q3 budget spreadsheet. We're 12% over on marketing
spend and need to decide whether to cut the conference budget or
reallocate from the training line item.

Can you review the numbers and send me your recommendation by Friday?
The CFO wants our input before the board meeting on Monday.

Also, the new vendor contract for cloud services needs your signature.
I left it on your desk.

Thanks,
Sarah
EOF

Now create the AGENTS.md file:

# Email Assistant Agent

## Project Type
Python CLI application

## Description
A command-line email assistant that reads email text (from files or stdin),
summarizes content, extracts action items, drafts replies, and sorts by priority.

## Tech Stack
- Python 3.8+ (standard library only)
- Text files for email input (one email per .txt file)
- JSON for configuration and output

## Conventions
- Use type hints
- Priority levels: URGENT, ACTION_REQUIRED, FYI, LOW
- Output summaries as structured text with clear sections
- Draft replies should match the formality level of the input

Save this as AGENTS.md in the project root, then start OpenCode:

opencode
2

Build the Email Assistant

Give OpenCode a detailed prompt and it will generate the complete email processing script.

Type this into OpenCode:

Create a Python script called email_assistant.py that processes emails.
It should have an interactive menu with these options:

1. Process single email (paste text or provide file path)
2. Batch process folder (read all .txt files from emails/ directory)
3. Show daily digest (summary of all processed emails)

For each email, it should:
- Extract sender, subject, date
- Summarize the key points in 2-3 bullet points
- Extract specific action items with deadlines
- Assign a priority: URGENT, ACTION_REQUIRED, FYI, or LOW
- Draft a professional reply

Store results in processed_emails.json for the digest feature.
Use keyword detection for priority: words like "urgent", "ASAP",
"deadline", "by Friday" should boost priority.

OpenCode will generate the complete script. Here's what you can expect:

  • An Email dataclass that holds parsed email fields
  • A parser that extracts headers (From, To, Subject, Date) and body text
  • Keyword-based priority scoring (no external AI API needed for basic classification)
  • A reply drafter that mirrors the original email's tone and addresses action items
  • JSON export for batch processing results
3

Run and Iterate

Test with your sample email and refine the output.

Run the email assistant:

python3 email_assistant.py

Try option 1 and point it at your sample email. You should see output like:

================================
  Email Assistant
================================

1. Process single email
2. Batch process folder
3. Show daily digest
4. Quit

Choice: 1
File path (or paste text): emails/sample1.txt

--- Analysis ---
From:     sarah@example.com
Subject:  Q3 Budget Review - Action Needed by Friday
Priority: ACTION_REQUIRED

Summary:
  - Q3 marketing spend is 12% over budget
  - Decision needed: cut conference budget or reallocate from training
  - New vendor contract needs physical signature

Action Items:
  [1] Review Q3 budget numbers and send recommendation (Due: Friday)
  [2] Sign vendor contract for cloud services (Due: ASAP)

--- Draft Reply ---
Hi Sarah,

Thanks for flagging this. I'll review the Q3 numbers today and
send my recommendation by Thursday EOD.

Regarding the vendor contract -- I'll sign it this afternoon.

Best,
[Your Name]

Iterate with OpenCode

Go back to OpenCode to improve the assistant:

# Make it smarter
Add sentiment analysis that detects if the sender seems frustrated,
neutral, or positive, and adjust the reply tone accordingly.

# Better parsing
Add support for .eml files and forwarded email chains with ">" quoting.
Parse the full thread and summarize each message separately.

# Templates
Add reply templates: "acknowledge and defer", "request more info",
"confirm and schedule meeting", "delegate to someone else".
Don't connect to real email APIs yet
Keep this as a text-processing tool first. Connecting to Gmail or Outlook requires OAuth credentials and introduces security complexity. Master the text processing, then consider API integration as a separate project. See the Agent Security guide for best practices.

Example Prompts to Try

Once the basic assistant works, extend it with these prompts:

# Meeting extraction
Add a feature that detects meeting requests and extracts the
proposed date, time, location, and attendees into a structured format.

# Response time tracking
Track how long emails have been waiting for a response. Flag
anything older than 24 hours as needing attention.

# Weekly report
Generate a weekly email activity report: how many emails processed,
average priority distribution, most common senders, action items
still open vs completed.

# Export
Add the ability to export the daily digest as a markdown file
that I can paste into my notes app.

What's Next?

You've built a working email assistant. Here are your options:

  • Build a web interface: Wrap it in Flask and deploy to Cloudflare Pages so you can paste emails in a browser.
  • Version control: Push your project to GitHub and track your iterations.
  • Add analytics: If you build a web version, add Umami to track usage patterns.
  • Try another agent: Same setup process, different task:

Ready for the Next Agent?

The pattern is always the same: create a folder, write AGENTS.md, give OpenCode the task. The only thing that changes is the prompt.