A local AI-powered email assistant that helps you manage, analyze, and respond to emails intelligently.
- π§ Connect to your email account (Gmail, Outlook, etc.)
- π€ AI-powered email analysis and categorization
- π NEW! Automatic email categorization (Primary, Social, Promotions, Notifications)
- π Date-based sub-categorization (Today, Yesterday, This Week, etc.)
- βοΈ Draft intelligent email responses
- π Summarize long email threads
- π Smart email search and filtering
- π Fully local and private (your choice of AI backend)
First, install the required Python packages:
pip install -r requirements.txtYou have two options:
- Sign up at https://platform.openai.com/
- Get your API key
- Set it in
.envfile
- Download Ollama from https://ollama.ai/
- Install it on your system
- Pull a model:
ollama pull llama3.2 - Set
AI_PROVIDER=ollamain.envfile
Create a .env file in the root directory:
# AI Configuration
AI_PROVIDER=openai # or 'ollama' for local
OPENAI_API_KEY=your-api-key-here # Only needed if using OpenAI
OLLAMA_MODEL=llama3.2 # Only needed if using Ollama
# Email Configuration
EMAIL_ADDRESS=your.email@gmail.com
EMAIL_PASSWORD=your-app-specific-password
# For Gmail: Use App Password (not your regular password)
# Guide: https://support.google.com/accounts/answer/185833
IMAP_SERVER=imap.gmail.com
SMTP_SERVER=smtp.gmail.com
IMAP_PORT=993
SMTP_PORT=587- Go to Google Account Settings
- Enable 2-Factor Authentication
- Generate an "App Password" at https://myaccount.google.com/apppasswords
- Use this app password in your
.envfile
- IMAP_SERVER:
outlook.office365.com - SMTP_SERVER:
smtp.office365.com - Use app password or OAuth (app password recommended)
Option A: Command Line Interface (CLI)
python email_assistant.pyOption B: REST API Server (for frontend integration)
python api_routes.pyOr using uvicorn:
uvicorn api_routes:app --reload --host 0.0.0.0 --port 8000Then access the interactive API documentation at: http://localhost:8000/docs
When you run the assistant for the first time, it will:
- Connect to your email account
- Load your recent emails
- Introduce itself and ask how it can help
The assistant understands natural language commands:
π§ Email Management:
- "Show me unread emails from today"
- "Summarize my inbox"
- "Find emails from John about the project"
- "What are my important emails?"
π Smart Categories (NEW!):
- "categorize" - Organize all emails into categories
- "show categories" - View category overview
- "show primary" - View important work/personal emails
- "show social" - View social media notifications
- "show promotions" - View marketing emails
- "show notifications" - View system notifications
- "show primary today" - Filter by category and date
βοΈ Writing Assistance:
- "Draft a reply to the latest email from Sarah"
- "Help me respond professionally to this complaint"
- "Write a follow-up email about the meeting"
π Analysis:
- "Summarize this email thread"
- "What's the sentiment of recent emails?"
βοΈ Commands:
- "help" - Show available commands
- "refresh" - Check for new emails
- "settings" - View current configuration
- "quit" - Exit the assistant
email-assistant/
βββ email_assistant.py # Main CLI application
βββ api_routes.py # FastAPI REST API server (NEW!)
βββ ai_backend.py # AI provider interface (OpenAI/Ollama)
βββ email_handler.py # Email operations (IMAP/SMTP)
βββ email_categorizer.py # Email categorization system
βββ utils.py # Helper functions
βββ requirements.txt # Python dependencies
βββ .env # Configuration (create this)
βββ README.md # This file
βββ API_DOCUMENTATION.md # Complete API reference (NEW!)
βββ API_QUICKSTART.md # Quick start for frontend devs (NEW!)
βββ CATEGORIES_GUIDE.md # Detailed guide for email categories
βββ .email_cache/ # Local cache for categorizations (auto-generated)
- β All processing happens locally on your machine
- β
Email credentials stored only in local
.envfile - β Option to use fully local AI (Ollama) - no data sent to cloud
- β No email content stored permanently
β οΈ Keep your.envfile secure and never commit it to version control
- Verify your email and app password are correct
- For Gmail, ensure you're using an App Password, not your regular password
- Check that IMAP is enabled in your email settings
- Verify IMAP_SERVER and ports are correct
- Check your firewall/antivirus settings
- Ensure you have internet connection
- If using OpenAI: Check your internet connection
- If using Ollama: Ensure Ollama is running (
ollama serve) - Try a smaller model (e.g.,
ollama pull llama3.2:3b)
The assistant now includes an intelligent categorization system that organizes your emails:
- π§ Primary: Important personal or work emails
- π₯ Social: Social media notifications and updates
- π·οΈ Promotions: Marketing emails and newsletters
- π Notifications: System notifications and receipts
- Today, Yesterday, This Week, This Month, Older
- Run
categorizeto analyze your emails - Use
show categoriesto see the overview - View specific categories:
show primary,show social, etc. - Filter by date:
show primary today,show social this week
For detailed information, see CATEGORIES_GUIDE.md
The assistant now includes a complete REST API for building web or mobile frontends!
python api_routes.py- β RESTful endpoints for all email operations
- β Interactive documentation at http://localhost:8000/docs
- β CORS enabled for frontend integration
- β Pydantic validation for request/response
- β Complete email management (fetch, categorize, search)
- β AI features (summarize, draft replies, queries)
// Fetch emails
const response = await fetch('http://localhost:8000/emails/fetch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ criteria: 'UNSEEN', limit: 20 })
});
const data = await response.json();
console.log(`Fetched ${data.count} emails`);- API_DOCUMENTATION.md - Complete API reference with examples
- API_QUICKSTART.md - Quick start guide for frontend developers
- Postman Collection - Import and test all endpoints
POST /emails/fetch- Fetch emailsPOST /emails/categorize- Categorize with AIGET /categories- Get category overviewPOST /categories/{category}/emails- View categoryPOST /ai/summarize- Summarize emailsPOST /ai/draft-reply- Draft reply with AIPOST /ai/search- Natural language search
Edit the system prompts in ai_backend.py to customize your assistant's personality and behavior.
Create custom email filters in email_handler.py to automatically categorize or prioritize emails.
Use Windows Task Scheduler or cron to run the assistant periodically for automated email monitoring.
MIT License - Feel free to modify and use as you wish!
Found a bug or want to add a feature? Contributions are welcome!