Automatically delete old emails from specified senders in your Gmail inbox. This bot runs on a schedule and displays activity via a web dashboard.
- 🗑️ Auto-delete old emails - Removes emails older than 5 days from configured senders
- 📊 Web Dashboard - Monitor bot activity and connection status in real-time
- 🔄 Scheduled runs - Runs daily to keep your inbox clean
- 🐳 Docker ready - Easy deployment with Docker Compose
- Coming Soon - More functions on the way, feel free to make suggestion and collaborate!
- Docker & Docker Compose
- Gmail account with 2-factor authentication enabled
- Gmail App Password
On a Linux server with Docker installed:
git clone https://github.com/MariosMoraitis/gmail_bot.git
cd gmail_βοτ
# Create config files
nano .env # Add EMAIL and PASSWORD
nano senders.json # Add email list
echo '{"connected": false, "timestamp": ""}' > status.json
touch log.txt
# Start bot
docker compose up -d --build
# View logs
docker compose logs -f gmail_schedulerUpdate docker-compose.yml to use .env instead of /etc/bot/.env if needed.
- scheduler.py - Runs deletion task on schedule
- bot.py - Connects to Gmail and deletes old emails
- app.py - Flask web server for dashboard
- templates/index.html - Dashboard UI
Edit scheduler.py to change frequency:
schedule.every().day.do(run_delete_old_emails) # Daily
schedule.every(6).hours.do(run_delete_old_emails) # Every 6 hours
schedule.every(1).minutes.do(run_delete_old_emails) # Every minute (testing)Change age in bot.py:
cutoff_date = datetime.now(timezone.utc) - timedelta(days=5) # Change 5 to desired days| Variable | Description |
|---|---|
EMAIL |
Your Gmail address |
PASSWORD |
Your Gmail App Password (not your regular password) |
- ✅ App password stored in
.env(not committed) - ✅ Credentials not logged
- ✅ IMAP over SSL/TLS
- ✅ Senders list customizable
- ⚠ Suggestion, move
.envat a new directory under\etc, so onlysudousers can access it (seedocker-compose.ymlfor configuration!)
- Verify EMAIL and PASSWORD in
.env - Enable 2FA and use App Password (not regular password)
- Check
docker compose logs gmail_scheduler
docker compose down
docker system prune -f
docker compose up -d --buildMIT