Python-based IMAP email assistant using Gemini AI for intelligent classification and summarization of unread emails. Built with system automation in mind.
.env
file with email and Gemini API credentialsgit clone https://github.com/Bugswriter/mailbot-ai.git
cd mailbot-ai
python -m venv venv
source venv/bin/activate # For Linux/macOS
pip install -r requirements.txt
Create a .env
file:
EMAIL_USERNAME=your_email@example.com
EMAIL_PASSWORD=your_email_password_or_app_password
IMAP_SERVER=imap.your-email-provider.com
GEMINI_API_KEY=your_gemini_api_key
Personal
, Spam
, Accounts
, or Promotions
prompt_template.py
python main.py
[Unit]
Description=MailBot - AI Email Classifier
After=network.target
[Service]
User=your_username
WorkingDirectory=/path/to/mailbot
ExecStart=/path/to/mailbot/venv/bin/python /path/to/mailbot/main.py
Restart=always
Environment="EMAIL_USERNAME=your_email"
Environment="EMAIL_PASSWORD=your_password"
Environment="IMAP_SERVER=imap.server"
Environment="GEMINI_API_KEY=your_key"
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reexec
sudo systemctl enable --now mailbot.service
Gemini classifies email using a prompt with strict rules and fallback logic:
Categories: Personal, Spam, Accounts, Promotions
- Personal: Human-written, conversational
- Spam: Unwanted, scammy, suspicious
- Accounts: OTPs, alerts, invoices, orders
- Promotions: Marketing/newsletter
If unsure, default to "Personal".
If domain is Gmail/Yahoo/Outlook/Zoho → Personal
This project is licensed under the GNU General Public License v3.0.