A powerful AI-powered email automation system that processes your Gmail in real-time, categorizes emails with local AI, and sends smart notifications to Telegram with interactive response capabilities.
- Instant monitoring - Checks Gmail every 30 seconds for new emails
- Immediate notifications - Get alerted within seconds of receiving important emails
- Background processing - Runs continuously without interrupting your workflow
- Ollama integration - Uses local
llama3.2:3bmodel (completely free) - Smart categorization - Automatically sorts emails into Important, Meetings, Personal, Newsletters, Promotions
- Intelligent filtering - Only sends notifications for emails that matter
- Selective notifications - Only for Important emails, Meeting requests, and Personal messages
- Interactive buttons - Reply, Schedule, View Full, Mark Done directly from Telegram
- AI-generated responses - Get suggested replies powered by local AI
- Meeting scheduling - Automatic calendar integration for meeting requests
- Local AI processing - No data sent to external AI services
- Secure OAuth - Uses Google's official authentication
- Persistent cache - Email data saved locally for reliable button interactions
Before setting up the Smart Email Assistant, ensure you have:
- Python 3.8+ installed on your system
- Gmail account with API access
- Telegram account for notifications
- Ollama installed with llama3.2:3b model
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.ai/install.sh | sh
# Windows - Download from https://ollama.ai/downloadDownload the AI model:
ollama pull llama3.2:3b# Clone or download the project
cd /path/to/smart-email-assistant
# Create virtual environment (recommended)
python3 -m venv venv
# Activate virtual environment
# macOS/Linux:
source venv/bin/activate
# Windows:
venv\\Scripts\\activate
# Install dependencies
pip install -r requirements.txt- Go to Google Cloud Console
- Create a new project or select existing one
- Enable APIs:
- Gmail API
- Google Calendar API
- Create credentials:
- Go to "Credentials" β "Create Credentials" β "OAuth 2.0 Client IDs"
- Application type: Desktop application
- Download the JSON file as
credentials.json
- Place the file in the project root directory
-
Create a bot:
- Open Telegram and search for
@BotFather - Send
/newbot - Choose name:
Smart Email Assistant - Choose username:
your_email_assistant_bot - Copy the bot token
- Open Telegram and search for
-
Get your Chat ID:
python3 get_chat_id.py
- Follow the instructions to get your chat ID
Create a .env file in the project root:
# Copy example configuration
cp .env.example .envEdit .env file:
# Google API Configuration
GOOGLE_API_KEY=your_google_api_key_here
# Gmail API Configuration
GMAIL_CREDENTIALS_FILE=credentials.json
GMAIL_TOKEN_FILE=token.json
# Google Calendar API Configuration
CALENDAR_CREDENTIALS_FILE=calendar_credentials.json
CALENDAR_TOKEN_FILE=calendar_token.json
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHAT_ID=your_telegram_chat_id_here
# Email Configuration
MAX_EMAILS=50
EMAIL_CATEGORIES=Important,Newsletters,Promotions,Meetings,Personal
# Demo Configuration
DEMO_MODE=false
AUTO_SEND=false
# Ollama Configuration (Local AI)
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=llama3.2:3bStart the complete real-time system:
python3 start_realtime.pyThis will:
- β Monitor Gmail in real-time (30-second intervals)
- β Process emails with local AI
- β Send smart Telegram notifications
- β Handle interactive button responses
- β Provide meeting scheduling capabilities
Process emails once:
python3 main.pyRun just the Telegram bot for handling callbacks:
python3 telegram_bot_server.pyβββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Gmail API βββββΊβ Smart Email βββββΊβ Telegram Bot β
β β β Assistant β β β
β β’ Email Fetch β β β β β’ Notifications β
β β’ Send Replies β β β’ AI Processing β β β’ Interactive β
β β’ Authenticationβ β β’ Categorization β β Buttons β
βββββββββββββββββββ β β’ Real-time Mon. β β β’ Response Gen. β
ββββββββββββββββββββ βββββββββββββββββββ
β
ββββββββββββββββββββ
β Local Ollama β
β β
β β’ llama3.2:3b β
β β’ 100% Free β
β β’ Privacy Safe β
ββββββββββββββββββββ
The system intelligently filters emails to prevent notification spam:
- Important emails - Account security, deadlines, urgent matters
- Meeting requests - Calendar invitations, scheduling emails
- Personal emails - Direct communications that could be business opportunities
- Newsletters - Marketing emails, subscription updates
- Promotions - Sales, discounts, shopping offers
- Spam/Low Priority - Automated notifications, social media alerts
/start- Show welcome message and setup info/status- Check system status/test- Send test notification
- βοΈ Reply - Generate AI-powered response
- π Schedule - Create calendar meeting
- π View Full - See complete email content
- β Mark Done - Archive and dismiss
- π Ignore - Dismiss without action
-
"TELEGRAM_BOT_TOKEN not found"
# Check your .env file has the correct token cat .env | grep TELEGRAM_BOT_TOKEN
-
"Gmail client not available"
# Re-authenticate with Gmail rm token.json python3 main.py -
"Ollama connection failed"
# Check Ollama is running ollama serve ollama run llama3.2:3b -
"Button callbacks not working"
# Check for cache files ls -la telegram_email_cache.pkl # Restart the real-time system python3 start_realtime.py
The system provides detailed logging:
- β Gmail authentication status
- π§ Email processing results
- π€ AI categorization decisions
- π± Telegram notification delivery
- π Real-time monitoring activity
Modify polling_interval in start_realtime.py:
monitor = RealTimeEmailMonitor(polling_interval=60) # Check every 60 secondsUpdate categories in .env:
EMAIL_CATEGORIES=Important,Newsletters,Promotions,Meetings,Personal,WorkCustomize priority levels in telegram_bot.py:
def get_notification_priority(self, email_data: Dict) -> str:
# Add your custom priority logicsmart-email-assistant/
βββ π email_assistant/ # Core application modules
β βββ gmail_client.py # Gmail API wrapper
β βββ telegram_bot.py # Telegram bot integration
β βββ telegram_handler.py # Callback handling
β βββ ollama_agents.py # Local AI agents
β βββ realtime_monitor.py # Real-time email monitoring
β βββ calendar_client.py # Google Calendar integration
β βββ controller.py # Main controller
βββ π tests/ # Test files
β βββ test_telegram.py # Telegram bot tests
β βββ test_ollama.py # AI agent tests
β βββ observation.txt # Test results
βββ π docs/ # Documentation
β βββ prd.txt # Product requirements
β βββ setup_instructions.md # Setup guide
βββ start_realtime.py # π Main real-time launcher
βββ main.py # Manual email processing
βββ get_chat_id.py # Telegram setup helper
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ README.md # This file
- Local AI Processing - All email analysis happens on your machine
- No Data Leakage - Emails never sent to external AI services
- OAuth Security - Uses Google's secure authentication
- Token Management - Automatic token refresh and secure storage
- Cache Encryption - Email cache files stored locally
- Daily Limit: 1 billion quota units (very generous)
- Per User: 250 quota units per 100 seconds
- Current Usage: ~29K units/day (0.003% of limit)
- Safety Rating: π’ Very Safe
- RAM: 2GB minimum (4GB recommended for Ollama)
- Storage: 2GB for Ollama model + logs
- Network: Stable internet for Gmail/Telegram APIs
- Check the troubleshooting section above
- Review logs for error messages
- Test individual components with test files
- Ensure all prerequisites are installed
Feel free to extend the system:
- Add new AI models
- Implement custom filters
- Create additional notification channels
- Build web dashboard interface
This project is open source and available under the MIT License.
- Ollama - For providing free local AI capabilities
- Google APIs - For Gmail and Calendar integration
- Telegram Bot API - For interactive notifications
- LangChain - For AI agent orchestration
Run the setup steps above and execute:
python3 start_realtime.pyYour intelligent email assistant will start monitoring your inbox and sending smart notifications to Telegram! π
Never miss an important email again while staying free from notification spam! β¨