Skip to content

xesta44/email-classifier

Repository files navigation

MailMind AI — Email Classifier & Auto-Responder

A production-ready demo of AI-powered email triage and automated reply generation.

Python FastAPI TailwindCSS

Overview

MailMind AI automatically classifies incoming emails into actionable categories and generates context-aware draft replies — with zero external API dependencies. Built as a portfolio demonstration of AI-augmented workflow automation.

Live capabilities:

  • 🏷️ 5-category classification — Urgent, Support Request, Sales Inquiry, Newsletter, Spam
  • 🤖 AI-generated replies — Template-based with smart variable substitution
  • 📊 Real-time dashboard — Category distribution chart, reply rate, priority queue
  • 🚀 One-click reply — Simulated send with full audit trail
  • 📱 Mobile responsive — Works on any screen size

Screenshots

Screenshots coming soon — run locally to see the UI

Dashboard Email View Classify Form
(chart + inbox table) (classification result + draft reply) (paste/submit form)

Tech Stack

Layer Technology
Backend Python 3.12, FastAPI
Templating Jinja2
Database SQLite via SQLAlchemy
Styling TailwindCSS (CDN)
Charts Chart.js 4
Classification Keyword/rule engine (no API key)
Replies Template-based with context extraction

Project Structure

email-classifier/
├── app.py              # FastAPI app, routes, startup
├── classifier.py       # Email classification engine
├── responder.py        # Auto-reply generator
├── database.py         # SQLite models + stats queries
├── sample_emails.py    # 10 demo emails + seed script
├── templates/
│   ├── base.html       # Navigation, layout shell
│   ├── index.html      # Email input form
│   ├── dashboard.html  # Stats + email table
│   └── email.html      # Classification result + reply
├── static/
│   └── style.css       # Custom overrides
├── requirements.txt
└── README.md

Quick Start

1. Clone & set up environment

git clone https://github.com/yourname/email-classifier.git
cd email-classifier

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

pip install -r requirements.txt

2. Run the server

uvicorn app:app --reload --host 0.0.0.0 --port 8000

Open http://localhost:8000 in your browser.

10 sample emails are automatically seeded on first run — the dashboard will have data immediately.

3. Seed manually (optional)

python sample_emails.py

How Classification Works

The classifier uses a weighted keyword-matching engine across 5 categories:

# Example: Urgent detection
KEYWORDS = ["urgent", "critical", "outage", "down", "asap", "emergency"]
# Subject-line keywords get 40% weight, body 60%
# Confidence scores normalized to 60-99% range for realism
Category Triggers Default Priority
Urgent outage, critical, ASAP, down, emergency Critical
Support Request help, error, bug, not working, issue High
Sales Inquiry pricing, demo, quote, purchase, enterprise High
Newsletter unsubscribe, digest, edition, noreply Low
Spam winner, lottery, free money, guaranteed Low

Reply Generation

Replies use structured templates with smart variable extraction:

  • Sender name — extracted from "First Last <email>" format
  • Company hint — inferred from email domain (ignores Gmail, Yahoo, etc.)
  • Issue summary — first meaningful sentence from email body
  • Case ID — randomly generated 5-digit reference number
  • Agent name — randomly selected from a pool of realistic names

API Endpoints

Method Path Description
GET / Email input form
POST /classify Classify & store email
GET /email/{id} View classified email + reply
POST /email/{id}/send-reply Mark reply as sent
GET /dashboard Stats dashboard
GET /api/stats JSON stats endpoint
GET /health Health check

Use Cases for Clients

This project demonstrates:

  1. Customer support automation — Route tickets automatically, reduce triage time
  2. Sales inbox management — Flag qualified leads, draft initial responses
  3. Spam filtering — Reduce noise in shared inboxes
  4. Email analytics — Track volume, categories, response rates

Extending This Project

  • Replace keyword classifier with a real LLM (OpenAI, Anthropic, local Ollama)
  • Add Gmail/Outlook OAuth integration for live inbox monitoring
  • Build a webhook endpoint to receive emails from SendGrid/Mailgun
  • Add Slack/Teams notifications for urgent emails
  • Export classified emails to CRM (Salesforce, HubSpot)

License

MIT — free to use for personal and commercial projects.


Built with FastAPI + TailwindCSS · No external AI APIs required for demo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors