Classify your Gmail inbox using a local LLM (Llama 3, Gemma, etc.) - 100% Privacy-Focused.
This project automates email organization by fetching unread emails from your Gmail, analyzing them with a locally running Large Language Model (LLM), and applying granular labels automatically. No email data leaves your machine for classification!
- 🔒 Privacy First: Uses a local LLM server (e.g., via
llama.cppor Ollama). Your emails are not sent to OpenAI or Anthropic. - 🏷️ Granular Classification: Automatically categorizes emails into:
bank-alert,finance,paymentsjob-application,interview,coding-assessmentnewsletter,promotions,spamsocial,travel,shopping- ...and more!
- 🤖 Smart & Context-Aware: Uses the email subject, snippet, and body to determine the best label.
- ⏱️ Automated: Runs as a background cron job (default: every 5 minutes).
- 🛠️ Easy Management: Includes a CLI helper to start/stop/monitor the service.
- Node.js: v18 or higher.
- Local LLM Server:
- Google Cloud Project:
- Enable the Gmail API.
- Create OAuth 2.0 Desktop App credentials.
- Download the
credentials.jsonfile.
git clone https://github.com/yourusername/gmail-classifier.git
cd gmail-classifiernpm installCreate a .env file in the project root based on the example:
cp .env.example .envEdit .env with your settings:
# LLM Configuration
LLM_BASE_URL=http://localhost:12434/engines/llama.cpp/v1
LLM_API_KEY=sk-local-key
LLM_MODEL=ai/gemma3
# Cron Schedule (Default: Every 5 minutes)
CRON_SCHEDULE=*/5 * * * *Note: The application will fail to start if LLM_BASE_URL or LLM_MODEL are missing.
Place your downloaded credentials.json file in the root directory of the project.
# It should look like this
ls -F
credentials.json .env package.json src/ ...The first time you run the app, it will open your browser to authenticate with Google.
npx ts-node src/index.tsWe provide a handy zsh helper script to manage the classifier as a background service.
-
Add to your shell: Add the following to your
~/.zshrc(or~/.bashrc):# Optional: Set custom project path if not in default location # export GMAIL_CLASSIFIER_DIR="/path/to/gmail-classifier" source /path/to/gmail-classifier/service.zsh
-
Reload shell:
source ~/.zshrc
-
Commands:
gmail-classifier start # 🚀 Start the background service gmail-classifier status # 🔍 Check if running gmail-classifier log # 📄 View real-time logs gmail-classifier stop # 🛑 Stop the service
Edit src/prompts.ts to add or remove categories. The system will automatically create new labels in Gmail if they don't exist.
export const getLabels = (): string[] => {
return [
"urgent",
"family",
// ... add your own
];
};You can tweak the system prompt in src/prompts.ts to better suit your specific needs or to give the LLM more context about how you like things filed.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License - see the package.json file for details.