Gmail + Google Calendar powered email workflow app with:
- Inbox Copilot: global assistant with tool calling + RAG (semantic search)
- Conversations: browse email threads with filters + pagination
- Priority Inbox: triage labels + priority score + streaming run progress
- Suggested Schedule: auto-plan follow‑ups onto your calendar (week grid) and confirm to create events
Demo (personal deployment)
Live web: https://app.mail-agents.net/
This is a personal deployment for demo purposes. For real email accounts and sensitive data, you are strongly encouraged to self‑host this project with your own Google account and database.
- Dashboard (
/dashboard): overview + quick actions + Suggested Schedule - Conversations (
/threads): browse email conversations - Priority Inbox (
/triage): view priority results + run “Update Priorities” - Thread Detail (
/thread/:threadId): full thread + Thread Chat (draft replies, save to Gmail) - Inbox Copilot: slide‑in panel from Dashboard, with session history
- Multi‑account support: switch between multiple Gmail accounts
- Priority Inbox (Triage):
- Labels:
NEEDS_REPLY,FYI,ARCHIVE,SPAM_LIKE - Priority score (0–1), sorted by importance
- Time filters (Today / 3 / 5 / 7 / 30 days)
- Pending triage indicator + cooldown based refresh
- Streaming progress (SSE) and shared progress state across Dashboard +
/triage
- Labels:
- Inbox Copilot (Assist Chat):
- Saves chat sessions to DB (
assist_chat_sessions) - Tool calling: triage query, RAG search, thread retrieval, draft generation
- Thread IDs in answers become clickable links in the UI
- “📖 How to Use This App” quick action
- Saves chat sessions to DB (
- Knowledge Base (RAG):
- Local embeddings using
all-MiniLM-L6-v2(SentenceTransformers) - Stored in Postgres +
pgvector(email_embeddings) - Background “silent sync & embed” task with cooldown to avoid repeated heavy work
- Local embeddings using
- Suggested Schedule (Calendar):
- Generates follow‑up blocks from Priority Inbox and places them into free calendar time
- Week grid view (drag / resize / select) then Confirm & Create to write events to Google Calendar
Important: This application processes sensitive email data, including message content, metadata, and calendar information. To protect your privacy and prevent data leakage:
- Self-host this application on your own infrastructure (AWS, GCP, Azure, or your own servers)
- Do not use third-party hosted instances unless you fully trust the operator
- Review and understand what data is stored and how it's processed
- Use strong authentication and keep your deployment secure
- Regularly update dependencies and monitor security advisories
By self-hosting, you maintain full control over:
- Email data storage and processing
- Database access and encryption
- API keys and OAuth tokens
- Network security and access controls
See deployment guides:
- Backend: See
backend/README.mdfor production deployment steps - Frontend: See
DEPLOY_FRONTEND.mdfor S3 + CloudFront deployment
Email-Agent/
├── backend/ # FastAPI + Python
│ ├── app/
│ │ ├── agents/ # Assist/Thread/Triage agents + tools
│ │ ├── routes/ # FastAPI routes
│ │ ├── services/ # Gmail/Calendar/RAG/Embedding/background tasks
│ │ ├── models.py # SQLAlchemy models
│ │ └── database.py # DB engine/session
│ ├── init_database.py # Create tables + add missing indexes (non-destructive)
│ ├── main.py # FastAPI entry
│ └── requirements.txt
├── frontend/ # React
│ ├── src/
│ │ ├── components/
│ │ └── pages/
│ └── package.json
└── client_secret.json # Google OAuth credentials (gitignored)
- Python 3.10+
- Node.js 18+
- PostgreSQL 15+
- Google Cloud OAuth credentials (Gmail + Calendar enabled)
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate backend/.env (example):
PORT=5001
DEBUG=True
FRONTEND_URL=http://localhost:3000
CORS_ORIGINS=http://localhost:3000
SESSION_SECRET=change-me-in-production
# Google OAuth
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
GOOGLE_REDIRECT_URI=http://localhost:5001/api/auth/google/callback
# Database
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=email_agent
DATABASE_USER=postgres
DATABASE_PASSWORD=...
# LLM (choose one)
LLM_PROVIDER=deepseek
DEEPSEEK_API_KEY=...
# or
# LLM_PROVIDER=openai
# OPENAI_API_KEY=...Initialize DB (creates tables, enables pgvector, and adds missing indexes without wiping data):
python init_database.pyRun backend:
python main.pyBackend:
- API base:
http://localhost:5001/api - Docs:
http://localhost:5001/docs
cd frontend
npm install
npm startOptional frontend/.env:
REACT_APP_API_URL=http://localhost:5001/apiFrontend:
http://localhost:3000
In Google Cloud Console:
- Enable Gmail API + Google Calendar API
- Create OAuth “Web application”
- Add redirect URI:
http://localhost:5001/api/auth/google/callback
Scopes used (see backend/app/config.py):
openidhttps://www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/userinfo.profilehttps://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.composehttps://www.googleapis.com/auth/calendar.events
GET /api/auth/google/loginGET /api/auth/google/callbackGET /api/auth/mePOST /api/auth/logout
GET /api/gmail/threads(supports pagination viapage_token)GET /api/gmail/threads/{thread_id}
POST /api/triage/run(SSE stream)GET /api/triage/results(supportsdays,limit,skip)GET /api/triage/stats(pending count)
POST /api/thread-chat/ask(SSE stream)POST /api/thread-chat/save-draft(saves to Gmail; auto-detects correct account)
POST /api/assist-chat/ask(SSE stream)GET /api/assist-chat/sessionsGET /api/assist-chat/sessions/{session_id}DELETE /api/assist-chat/sessions/{session_id}
GET /api/calendar/suggestionsPOST /api/calendar/confirm
Security Best Practices:
- Self-host on your own infrastructure to maintain control over sensitive email data
- Set
DEBUG=Falsein production - Use a strong, randomly generated
SESSION_SECRET - Set
FRONTEND_URL+CORS_ORIGINSto your deployed frontend origin(s) - Update
GOOGLE_REDIRECT_URIto your deployed backend callback URL and update OAuth redirect URIs in Google Cloud - Use a managed Postgres (e.g. Cloud SQL / RDS) with encryption at rest and ensure
pgvectoris available - Enable HTTPS in production (required for OAuth)
- Restrict database access to only the application server
- Regularly rotate OAuth tokens and API keys
- Monitor access logs for suspicious activity
- Keep dependencies updated to patch security vulnerabilities
- Author: Haoji Bian
- Email: haoji.bian@mail-agents.net
- Website: https://mail-agents.net
- GitHub: https://github.com/Haoj1/Email-Agent
This project is licensed under the MIT License.
Copyright (c) 2026 Haoji Bian
