AI-native Email Inbox (Alpha)
DispatchMail is an open source locally run (though currently using OpenAI for queries) AI-powered email assistant that helps you manage your inbox. It monitors your email, processes it with an AI agent based on your prompts, and provides a (locally run) web interface for managing drafts/responses, and instructions.
- π€ AI-powered email processing through OpenAI
- π± Web interface for inbox management
- π― Customizable email filtering and whitelist rules to only give the AI access to specific types of emails
- π Draft generation and email composition
- π·οΈ Automatic Email labeling and organization (including archival)
- ποΈ Local SQLite database (no cloud dependencies for storage)
- π΅οΈββοΈ Customizable LLM powered deep research on sender profiles
This is an early alpha/prototype project, based on the Pete Koomen's article, AI Horseless Carriages. It's made to run locally for developers who want to tinker. We welcome feedback and plan to improve and expand based on user feedback and interest. We would love to offer a managed, more polished version of this if there is interest as we believe the future of AI Agents working with Humans is collaborative and will require more Human/Agent "multiplayer" spaces.
Long run, we want to not just give AI Agents a place to work in your inbox, but their own AI-native email as well as our colleagues. For now, this is a helpful babystep, and we welcome feedback, contributions, and discussion.
- Python 3.8+
- Node.js 16+ (for web interface)
- Gmail account with 2FA enabled
- OpenAI API key (required for AI features)
-
Clone the repository:
git clone https://github.com/dbish/DispatchMail.git cd DispatchMail
-
Run the setup script:
python setup.py
This will:
- Install all dependencies
- Initialize the SQLite database
- Create a sample configuration file
- Guide you through account setup
-
Configure your credentials:
- Edit
web-app/api/credentials.py
with your OpenAI API key - For Gmail, create an App Password: https://support.google.com/mail/answer/185833 (add a feature request for login with Google if you'd prefer that :) )
- Edit
-
Start the services:
# Option A: Use the startup script (recommended) python start.py # Option B: Start manually # Terminal 1: Start the web API cd web-app python api/api.py # Terminal 2: Start the frontend (in another terminal) cd web-app npm run dev
-
Open http://localhost:5173 in your browser and set up your email account
If you prefer to set up manually:
# Backend dependencies
cd web-app/api
pip install -r requirements.txt
# Frontend dependencies
cd ../
npm install
Create web-app/api/credentials.py
:
# OpenAI API Key
OPENAI_API_KEY = 'your-openai-api-key'
python -c "from database import db; print('Database initialized!')"
You can add user accounts through the web interface or programmatically:
python -c "
from database import db
db.put_user('[email protected]', 'imap.gmail.com', 'your-app-password')
print('User added!')
"
For Gmail accounts, you need:
- Enable 2FA: Go to your Google Account settings and enable 2-factor authentication
- Generate App Password:
- Go to Google Account > Security > App passwords
- Generate a new app password for "Mail"
- Use this password when setting up your account in the web interface
Configure whitelist rules via the web interface to control which emails are processed:
- Sender-based rules: Filter by sender email address
- Subject-based rules: Filter by keywords in subject line
- AI-based rules: Use natural language to describe filtering criteria
Customize the AI behavior by setting:
- Reading Prompt: Instructions for how the AI should analyze emails
- Draft Prompt: Instructions for how the AI should generate responses
The SQLite database contains three main tables:
emails
: Stores email content and processing statusmetadata
: Stores configuration, prompts, and user preferencesusers
: Stores IMAP account credentials
The web API provides REST endpoints for:
GET /api/emails
- List emailsGET /api/emails/<id>
- Get specific emailPOST /api/emails/<id>/draft
- Update draftGET/POST /api/prompts/reading
- Manage reading promptGET/POST /api/prompts/draft
- Manage draft promptGET/POST /api/whitelist
- Manage whitelist rulesGET/POST /api/users
- Manage user accountsGET /api/process_emails
- Process unprocessed emailsGET /api/get_updates
- Retrieve new emails from server
- All data is stored locally in SQLite
- Email credentials are stored in the database
- OpenAI API key is stored in
web-app/api/credentials.py
- Consider using environment variables for production deployments
- The application binds to
0.0.0.0:5000
by default
-
Authentication Failed:
- Make sure you're using an App Password, not your regular password
- Verify 2FA is enabled on your Google account
-
Database Errors:
- Delete
dmail.db
and restart to reset the database - Check file permissions in the project directory
- Delete
-
Port Conflicts:
- Web API runs on port 5000
- Frontend runs on port 5173
- Make sure these ports are available
-
OpenAI API Errors:
- Verify your API key is correct in
web-app/api/credentials.py
- Check your OpenAI account has sufficient credits
- Verify your API key is correct in
Check logs in the logs/
directory:
# View API logs
tail -f logs/api.log
# View frontend logs
tail -f logs/frontend.log
DispatchMail/
βββ database.py # SQLite database interface
βββ start.py # Service startup script
βββ setup.py # Setup script
βββ web-app/ # Frontend and API
β βββ api/
β β βββ api.py # Flask web API
β β βββ inbox.py # Email processing logic
β β βββ agent.py # AI processing
β β βββ gmail.py # Gmail IMAP integration
β β βββ credentials.py # API keys and credentials
β β βββ requirements.txt # Python dependencies
β βββ src/ # React frontend
β βββ package.json # Node.js dependencies
βββ logs/ # Application logs
- Email Retrieval: The API connects to your Gmail via IMAP to fetch new emails
- Filtering: Emails are filtered based on whitelist rules you configure
- AI Processing: Filtered emails are processed by OpenAI GPT for classification and draft generation
- Web Interface: The React frontend provides a UI for managing emails and drafts
- Local Storage: All data is stored locally in SQLite for privacy
- New AI Prompts: Modify
web-app/api/agent.py
- New Filters: Extend
web-app/api/inbox.py
- New API Endpoints: Add to
web-app/api/api.py
- Frontend Changes: Modify files in
web-app/src/
Apache-2.0 - see LICENSE file for details
Copyright (c) 2025 Datadog https://www.datadoghq.com
For issues and questions:
- Check the troubleshooting section above
- Review the console logs for error messages
- Check the logs in the
logs/
directory - Open an issue in the repository