Skip to content

About

AI-powered Gmail automation pipeline in Python - monitors your inbox in real-time, then categorizes, summarizes, and rates each email on a 5-level importance scale, organizing results into a structured folder hierarchy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mail Flow Manager

An automated email processing system that monitors Gmail and processes incoming emails through a complete AI-powered OOP pipeline.

πŸš€ Features

  • Gmail Monitoring: Real-time monitoring for new emails
  • Smart Categorization: AI-powered email classification (Promotion, Spam, Work, Personal, Finance, Other)
  • Intelligent Summarization: Extracts only essential information from emails
  • 5-Level Importance Rating: Rates emails on scale: low β†’ medium β†’ high β†’ urgent β†’ critical
  • Dual Storage System: Raw emails in mails/ and evaluated emails organized in evaluated/category/priority/
  • OOP Architecture: Clean, maintainable code following DRY principles

πŸŽ₯ Video Showcase

Mail Flow Manager Demo

Click the image above to watch the Mail Flow Manager in action! See how it automatically processes emails through the complete AI pipeline.

πŸ“ Project Structure

Mailflow-Manager/
β”œβ”€β”€ config.py              # Configuration settings
β”œβ”€β”€ main.py                # Main application entry point
β”œβ”€β”€ test.py                # Component testing script
β”œβ”€β”€ requirements.txt       # Dependencies
β”œβ”€β”€ mails/                 # Raw email storage (original content only)
β”œβ”€β”€ evaluated/             # Processed emails organized by category and priority
β”‚   β”œβ”€β”€ work/
β”‚   β”‚   β”œβ”€β”€ high/
β”‚   β”‚   β”œβ”€β”€ medium/
β”‚   β”‚   └── low/
β”‚   └── personal/
β”‚       β”œβ”€β”€ urgent/
β”‚       └── medium/
└── modules/
    β”œβ”€β”€ base_ai_processor.py   # Base class for AI processors (DRY principle)
    β”œβ”€β”€ ai_prompts.py          # Centralized AI prompts for all processors
    β”œβ”€β”€ gmailmonitor.py       # Gmail monitoring & main pipeline
    β”œβ”€β”€ categorizer.py        # Email categorization
    β”œβ”€β”€ summarizer.py         # Email summarization  
    └── importance.py         # 5-level importance rating

πŸ—οΈ OOP Architecture

  • BaseAIProcessor: Abstract base class eliminating code duplication across AI modules
  • AIPrompts: Centralized prompt management for all AI processors
  • Inheritance: All AI processors inherit common API handling and error management
  • Polymorphism: Consistent process() method interface across all modules
  • Encapsulation: Clean separation of concerns between monitoring and processing

πŸ”§ Setup

  1. Install Dependencies

    pip install -r requirements.txt
  2. Environment Configuration Create a .env file in the root directory:

    API_KEY_OPENAI=your_g4f_api_key_here
    MAIL_USERNAME=your_gmail@gmail.com
    MAIL_APP_PASSWORD=your_gmail_app_password
  3. Gmail App Password Setup

    • Enable 2-factor authentication on your Google account
    • Generate an app password for this application
    • Use the app password (not your regular password) in the .env file

🎯 Usage

Run the Mail Monitor

python main.py

Or just run bash script

run_mailflow.bat

Test Individual Components

python test.py

πŸ”„ Email Processing Pipeline

When a new email arrives, it goes through this OOP-based pipeline:

  1. πŸ“§ Gmail Monitor - Detects new email and extracts content
  2. πŸ’Ύ Raw Storage - Saves original email to mails/ folder
  3. πŸ“‚ Categorizer - Classifies the email into categories
  4. πŸ“ Summarizer - Creates a concise summary of essential information
  5. ⭐ Importance Rater - Rates importance on 5-level scale
  6. πŸ“Š Evaluated Storage - Saves processed email to evaluated/category/priority/ folders

πŸ“„ File Organization

Raw Emails (mails/ folder)

Format: YYYY-MM-DD_Subject.txt

Subject: Meeting Request - Project Review
From: manager@company.com
Date: 2026-01-30 14:30:15

============================================================
Content:
[Original email content only...]

Evaluated Emails (evaluated/category/priority/ folders)

Format: YYYY-MM-DD_Subject.txt

Subject: Meeting Request - Project Review
From: manager@company.com
Date: 2026-01-30 14:30:15
Category: Work
Importance: medium
Summary: Meeting request for project review. Action required: respond with availability.

============================================================
Original Message:
[Original email content...]

βš™οΈ Configuration

The config.py file handles all configuration:

  • API keys for AI processing
  • Gmail credentials
  • Validation of required settings

πŸ§ͺ Testing

Use test.py to verify individual components:

  • Categorizer functionality
  • Summarizer performance
  • 5-level importance rating accuracy
  • Complete pipeline testing

πŸ” Security Notes

  • Uses Gmail App Passwords (secure authentication)
  • API keys stored in environment variables
  • No credentials stored in code

πŸ“Š 5-Level Importance Scale

  • LOW: Routine emails, newsletters, non-urgent notifications, social updates
  • MEDIUM: Regular work communications, meeting requests, follow-ups, planned tasks
  • HIGH: Important business matters, time-sensitive requests, deadline reminders
  • URGENT: Critical deadlines (24-48 hours), client issues, system problems
  • CRITICAL: Emergency situations, security alerts, system failures, legal issues

πŸ› οΈ Customization

The OOP structure makes customization easy:

  • AI Prompts: All prompts centralized in ai_prompts.py for easy modification
  • Email categories: Update categories in categorizer.py
  • Summary style: Modify prompt in ai_prompts.py
  • Importance levels: Adjust scale in importance.py
  • File naming: Change format in gmailmonitor.py
  • Add new processors: Extend BaseAIProcessor and add prompts to AIPrompts

πŸ“ License

See LICENSE file for details.

About

AI-powered Gmail automation pipeline in Python - monitors your inbox in real-time, then categorizes, summarizes, and rates each email on a 5-level importance scale, organizing results into a structured folder hierarchy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages