A Flask web application that uses Google's Gemini AI to automatically categorize and label your Gmail messages.
- 🔐 Secure Google OAuth2 authentication
- 🤖 AI-powered email analysis using Gemini
- 🏷️ Automatic custom label creation and management
- 📧 Smart categorization of emails
- 🎨 Clean, modern user interface
- 🔄 Real-time label updates
- Python 3.8 or higher
- Google Cloud Project with:
- Gmail API enabled
- Gemini API enabled
- Google OAuth2 credentials (credentials.json)
- Gemini API key
- Clone the repository:
git clone <repository-url>
cd gmail-smart-labeler- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up your credentials:
- Place your Google OAuth2 credentials file as
credentials.jsonin the project root - Create a
.envfile in the project root with the following content:GEMINI_API_KEY=your_gemini_api_key_here FLASK_SECRET_KEY=your_secret_key_here
- Place your Google OAuth2 credentials file as
-
Environment Variables:
- Create a
.envfile in the project root - Add your Gemini API key and Flask secret key
- Never commit the
.envfile to version control
- Create a
-
(Optional) Configure Flask settings in
app.py:
app.config.update({
'SESSION_COOKIE_NAME': 'gmail-auth-session',
'PERMANENT_SESSION_LIFETIME': 600,
'SESSION_COOKIE_SECURE': False,
'SESSION_COOKIE_SAMESITE': 'Lax'
})- Start the Flask application:
python app.py- Open your web browser and navigate to:
http://localhost:5000
- Sign in with your Google account
- The application will:
- Fetch your recent emails
- Analyze them using Gemini AI
- Create appropriate custom labels
- Apply labels to your emails
- Display the results in the interface
- Authentication: Uses Google OAuth2 for secure access to your Gmail account
- Email Analysis:
- Fetches email content and headers
- Uses Gemini AI to analyze the content
- Generates appropriate single-word topic labels
- Label Management:
- Creates new custom labels if needed
- Applies labels to relevant emails
- Maintains a clean interface showing only custom labels
- Uses secure OAuth2 authentication
- Implements session management
- Stores sensitive information in environment variables
- Follows Google's security best practices
- Only works with custom labels (ignores system labels)
- Limited to analyzing the 10 most recent emails
- Requires internet connection for API access
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gmail API
- Google Gemini AI
- Flask Framework