A small Python service that scans your Gmail inbox and drafts/sends polite replies using either OpenAI or a local Ollama model.
- ✅ OpenAI or Ollama as the LLM backend
- ✅ Safer system prompt (configurable)
- ✅ CLI: one-shot or looping mode, adjustable interval
- ✅ Dry-run mode (preview replies without sending)
- ✅ Creates/uses a custom Gmail label (default:
AutoReplied) - ✅ Simple exponential backoff for transient Gmail/API errors
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install google-auth-oauthlib google-auth-httplib2 requests openai- Go to Google Cloud Console → create project → Enable Gmail API.
- Create OAuth client ID (Desktop) and download credentials.json into this project folder.
- First run will open a browser for consent; a token.json will be saved.
You can customize paths via env:
- GMAIL_CREDENTIALS_FILE (default credentials.json)
- GMAIL_TOKEN_FILE (default token.json)
- GMAIL_LABEL (default AutoReplied)
- Choose an LLM backend
OpenAI (default)
export OPENAI_API_KEY=sk-... # put your key here
export OPENAI_MODEL=gpt-4o-mini # optionalOllama
# Make sure Ollama is running locally and the model is pulled
# e.g., ollama run phi3:3.8b or ollama pull llama3
export OLLAMA_BASE="http://127.0.0.1:11434"
export OLLAMA_MODEL="phi3:3.8b" Running
# Use Ollama instead of OpenAI
python main.py --provider ollama
# Change interval to 30s, default 10s
python main.py --interval 30
# Dry run (draft but do not send/label)
python main.py --dry-run
# Provide your own system prompt
python main.py --context "You're a formal, brief assistant that..."