Skip to content

An intelligent email automation platform powered by AI that transforms how you manage, analyze, and respond to emails.

Notifications You must be signed in to change notification settings

ImenBenAmar/SmartAI-hack-sofrecom-tunisie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“§ SmartMail AI - Email Automation Platform

An intelligent email automation platform powered by AI that transforms how you manage, analyze, and respond to emails.

🎬Demo

Next.js FastAPI TypeScript Python License

🌟 Overview

SmartMail AI is a comprehensive email automation solution that combines the power of modern web technologies with advanced AI language models. It provides a seamless interface for Gmail integration, intelligent email processing, task detection, auto-reply generation, document analysis, and calendar management.

Built for the Sofrecom Tunisia Hackathon, this project demonstrates the potential of AI-driven workflow automation in enterprise email management.

Key Highlights

  • πŸ€– AI-Powered Analysis: Semantic analysis, sentiment detection, and urgency classification
  • 🌍 Multi-Language Support: Automatic translation from French to English
  • πŸ“Ž Smart Attachment Processing: OCR for PDFs and images with text extraction
  • πŸ“… Calendar Integration: Intelligent meeting scheduling with Google Calendar
  • πŸ’¬ Auto-Reply Generation: Context-aware email responses
  • πŸ” RAG Question Answering: Ask questions about email content with AI
  • πŸ“Š Document Classification: Automatic theme detection and categorization
  • ⚑ Real-Time Processing: Instant analysis with live status updates

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SmartMail AI Platform                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚    Frontend      │◄─────────►│     Backend      β”‚        β”‚
β”‚  β”‚   (Next.js 15)   β”‚   REST    β”‚    (FastAPI)     β”‚        β”‚
β”‚  β”‚                  β”‚    API    β”‚                  β”‚        β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚           β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚        β”‚
β”‚  β”‚  β”‚ Gmail UI   β”‚  β”‚           β”‚  β”‚ LLM Client β”‚  β”‚        β”‚
β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚           β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚        β”‚
β”‚  β”‚  β”‚ Email      β”‚  β”‚           β”‚  β”‚ RAG Engine β”‚  β”‚        β”‚
β”‚  β”‚  β”‚ Analysis   β”‚  β”‚           β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚        β”‚
β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚           β”‚  β”‚ OCR        β”‚  β”‚        β”‚
β”‚  β”‚  β”‚ Calendar   β”‚  β”‚           β”‚  β”‚ Processor  β”‚  β”‚        β”‚
β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚           β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚        β”‚
β”‚  β”‚  β”‚ Chatbot    β”‚  β”‚           β”‚  β”‚ Calendar   β”‚  β”‚        β”‚
β”‚  β”‚  β”‚ Interface  β”‚  β”‚           β”‚  β”‚ Service    β”‚  β”‚        β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚           β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚           β”‚                              β”‚                   β”‚
β”‚           β”‚                              β”‚                   β”‚
β”‚           β–Ό                              β–Ό                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚  Gmail API       β”‚           β”‚  AI Models       β”‚        β”‚
β”‚  β”‚  Google Calendar β”‚           β”‚  - NVIDIA Llama  β”‚        β”‚
β”‚  β”‚  NextAuth.js     β”‚           β”‚  - Mistral AI    β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚  - ChromaDB      β”‚        β”‚
β”‚                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Features

πŸ“¨ Email Management

  • Gmail Integration: Seamless access to your Gmail inbox
  • Thread Viewer: Read email conversations with full history
  • Smart Filters: Filter by unread, starred, sender, or date
  • Search: Powerful search across all emails
  • Attachment Viewer: Preview and download attachments

🧠 AI-Powered Analysis

  • Semantic Analysis: Understand email intent, tone, and type
  • Sentiment Detection: Identify positive, negative, or neutral sentiment
  • Urgency Classification: Detect time-sensitive emails automatically
  • Task Extraction: Automatically identify action items and to-dos
  • Key Points Summary: Get concise summaries of long emails

πŸ”„ Intelligent Automation

  • Auto-Translation: Convert French emails to English instantly
  • Auto-Reply: Generate contextually appropriate responses
  • Meeting Detection: Identify meeting proposals in emails
  • Calendar Scheduling: Automatically schedule meetings with conflict detection
  • Batch Processing: Process multiple emails simultaneously

πŸ“Ž Document Processing

  • OCR Technology: Extract text from PDFs and images (PNG, JPG, JPEG)
  • Format Support: Handle TXT, DOCX, PDF, and image files
  • Text Extraction: Accurate text recognition with Tesseract OCR
  • Metadata Extraction: File size, type, creation date

πŸ” Advanced Search & Q&A

  • RAG (Retrieval-Augmented Generation): Ask questions about email content
  • Vector Search: Semantic search using ChromaDB
  • Context-Aware Answers: Get accurate answers based on email context
  • Document Classification: Automatically categorize documents by theme

πŸ“… Calendar Integration

  • Availability Check: View free time slots for the next 7 days
  • Smart Scheduling: Avoid conflicts when booking meetings
  • Meeting Analysis: Extract meeting details from email text
  • Event Creation: Create Google Calendar events directly

πŸ’¬ Interactive Chatbot

  • Conversational AI: Natural language interface for email queries
  • Quick Actions: Pre-defined shortcuts for common tasks
  • Multi-Turn Conversations: Context-aware dialogue
  • Email Insights: Ask questions about your inbox

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript 5.0
  • Authentication: NextAuth.js v5
  • Styling: Tailwind CSS
  • UI Components: Radix UI, Lucide Icons
  • State Management: React Hooks
  • API Integration: Native Fetch with custom wrappers

Backend

  • Framework: FastAPI
  • Language: Python 3.8+
  • AI Models:
    • NVIDIA Llama 3 (8B & 70B Instruct)
    • Mistral AI (mistral-small)
  • Vector Store: ChromaDB
  • Embeddings: HuggingFace (sentence-transformers)
  • OCR: Tesseract, OpenCV, pytesseract
  • Document Processing: python-docx, PyPDF2
  • Calendar: Google Calendar API

Infrastructure

  • Authentication: Google OAuth 2.0
  • APIs: Gmail API, Google Calendar API
  • Caching: File-based translation cache
  • Database: ChromaDB for vector storage

πŸ“ Project Structure

projet_email_automation/
β”œβ”€β”€ frontend/                    # Next.js frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # Next.js pages (App Router)
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx        # Landing page
β”‚   β”‚   β”‚   β”œβ”€β”€ inbox/          # Gmail inbox pages
β”‚   β”‚   β”‚   └── api/            # API routes (NextAuth, Gmail proxy)
β”‚   β”‚   β”œβ”€β”€ components/         # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ inbox/          # Email UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ chatbot/        # Chatbot interface
β”‚   β”‚   β”‚   β”œβ”€β”€ calendar/       # Calendar widgets
β”‚   β”‚   β”‚   └── ui/             # Reusable UI elements
β”‚   β”‚   β”œβ”€β”€ services/           # API service layer
β”‚   β”‚   β”œβ”€β”€ lib/                # Utilities and helpers
β”‚   β”‚   β”œβ”€β”€ auth/               # NextAuth configuration
β”‚   β”‚   └── types/              # TypeScript definitions
β”‚   β”œβ”€β”€ public/                 # Static assets
β”‚   β”œβ”€β”€ .env.local              # Environment variables (not in git)
β”‚   β”œβ”€β”€ next.config.js          # Next.js configuration
β”‚   └── package.json            # Dependencies
β”‚
β”œβ”€β”€ backend/                     # FastAPI backend application
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ main.py             # FastAPI entry point
β”‚   β”‚   β”œβ”€β”€ routes/             # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ email.py        # Email processing
β”‚   β”‚   β”‚   β”œβ”€β”€ attachment.py   # Attachment handling
β”‚   β”‚   β”‚   β”œβ”€β”€ calendar.py     # Calendar integration
β”‚   β”‚   β”‚   β”œβ”€β”€ rag.py          # RAG Q&A
β”‚   β”‚   β”‚   └── classification.py # Document classification
β”‚   β”‚   └── models/             # Pydantic models
β”‚   β”œβ”€β”€ modules/                # Core business logic
β”‚   β”‚   β”œβ”€β”€ llm_client.py       # AI model client
β”‚   β”‚   β”œβ”€β”€ rag_processor.py    # RAG engine
β”‚   β”‚   β”œβ”€β”€ attachment_processor.py # OCR & file processing
β”‚   β”‚   └── calendar_service.py # Google Calendar service
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ .env                # Backend environment variables
β”‚   β”‚   └── client_secret.json  # Google OAuth credentials
β”‚   β”œβ”€β”€ data/                   # Data storage
β”‚   β”‚   β”œβ”€β”€ translation_cache/  # Cached translations
β”‚   β”‚   β”œβ”€β”€ chroma_db_api/      # RAG vector store
β”‚   β”‚   └── chroma_db_classification/ # Classification vectors
β”‚   β”œβ”€β”€ requirements.txt        # Python dependencies
β”‚   └── tests/                  # Test suites
β”‚
└── README.md                    # This file

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm/yarn
  • Python 3.8+
  • Tesseract OCR (for attachment processing)
  • Google Cloud Project with Gmail & Calendar APIs enabled

1. Clone the Repository

git clone https://github.com/your-username/projet_email_automation.git
cd projet_email_automation

2. Setup Backend

Install Dependencies

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

Configure Environment

Create backend/config/.env:

# AI Models
NVIDIA_API_KEY_LLAMA3_8B=your_nvidia_api_key_8b
NVIDIA_API_KEY_LLAMA3_70B=your_nvidia_api_key_70b
CLOUD_ADAPTER_API_KEY=your_mistral_api_key
MISTRAL_MODEL=mistral-small

# Optional: Local Llama
LOCAL_LLAMA_API_BASE_URL=http://localhost:11434
LOCAL_LLAMA_MODEL_NAME=llama3

Start Backend

python api/main.py
# Backend runs on http://127.0.0.1:8002

3. Setup Frontend

Install Dependencies

cd ../frontend
npm install

Configure Environment

Create frontend/.env.local:

# Google OAuth
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GMAIL_SCOPES=openid email profile https://www.googleapis.com/auth/gmail.readonly

# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-random-secret-32-chars

# Backend API
NEXT_PUBLIC_BACKEND_URL=http://127.0.0.1:8002

Start Frontend

npm run dev
# Frontend runs on http://localhost:3000

4. Access the Application

  1. Open http://localhost:3000
  2. Click "Sign In" and authenticate with Google
  3. Grant Gmail permissions
  4. Start using SmartMail AI! πŸŽ‰

πŸ“– Documentation

Detailed Guides

Key Endpoints

Frontend (Next.js API Routes)

  • GET /api/gmail/threads - List Gmail threads
  • GET /api/gmail/threads/[threadId] - Get thread details
  • GET /api/gmail/messages/[id] - Get message details

Backend (FastAPI)

  • POST /api/translate - Translate email
  • POST /api/analyze - Semantic analysis
  • POST /api/summary - Generate summary
  • POST /api/tasks - Detect tasks
  • POST /api/reply - Generate auto-reply
  • POST /api/attachment/process - Process attachment
  • POST /api/rag/ask - RAG question answering
  • POST /api/classification/themes - Classify document
  • GET /api/calendar/availability - Check availability
  • POST /api/calendar/schedule - Schedule event

🎯 Use Cases

1. Email Triage & Prioritization

  • Automatically detect urgent emails
  • Classify emails by type (meeting, task, information)
  • Filter and sort inbox intelligently

2. Multilingual Communication

  • Translate French emails to English
  • Maintain context and tone in translations
  • Support for business communication

3. Task Management

  • Extract action items from emails
  • Assign tasks with deadlines
  • Track pending work items

4. Meeting Coordination

  • Detect meeting requests in emails
  • Check calendar availability
  • Schedule meetings automatically
  • Avoid double-bookings

5. Document Analysis

  • Extract text from scanned documents
  • Classify documents by theme
  • Answer questions about document content

6. Customer Support

  • Generate professional email responses
  • Maintain consistent tone across replies
  • Reduce response time

πŸ§ͺ Testing

Frontend Testing

cd frontend
npm run type-check  # TypeScript type checking
npm run lint        # ESLint
npm run build       # Production build test

Backend Testing

cd backend
python tests/test_pipeline.py  # API integration tests

# Manual testing with curl
curl -X GET http://127.0.0.1:8002/health
curl -X POST http://127.0.0.1:8002/api/translate \
  -H "Content-Type: application/json" \
  -d '{"subject":"Test","message":"Bonjour"}'

Interactive API Testing

  1. Start the backend
  2. Visit http://127.0.0.1:8002/docs
  3. Use Swagger UI to test all endpoints

πŸ› Troubleshooting

Common Issues

"Invalid Date" in Frontend

Solution: Ensure dateFormatter.ts is properly imported:

import { formatEmailDate } from "@/utils/dateFormatter";
<span>{formatEmailDate(email.date)}</span>

Backend Connection Error

  • Check backend is running: http://127.0.0.1:8002/health
  • Verify NEXT_PUBLIC_BACKEND_URL in frontend .env.local
  • Check CORS settings in backend/api/main.py

Authentication Issues

  • Verify Google OAuth credentials in .env.local
  • Check Gmail API is enabled in Google Cloud Console
  • Ensure redirect URIs match in Google Console

AI Model Errors (404)

  • Verify API keys in backend/config/.env
  • Check model names are correct
  • Test with Mistral if NVIDIA keys expired

πŸ”’ Security

  • OAuth 2.0: Secure Google authentication
  • HTTP-Only Cookies: Session tokens stored securely
  • API Key Protection: Backend keys never exposed to client
  • CORS Configuration: Restricted to authorized origins
  • Input Validation: Pydantic models for request validation
  • Rate Limiting: Protection against API abuse (future enhancement)

🌍 Environment Variables

Frontend (.env.local)

GOOGLE_CLIENT_ID=              # Google OAuth Client ID
GOOGLE_CLIENT_SECRET=          # Google OAuth Client Secret
GMAIL_SCOPES=                  # Gmail API scopes
NEXTAUTH_URL=                  # NextAuth callback URL
NEXTAUTH_SECRET=               # NextAuth encryption key
NEXT_PUBLIC_BACKEND_URL=       # Backend API URL

Backend (config/.env)

NVIDIA_API_KEY_LLAMA3_8B=      # NVIDIA API key (8B model)
NVIDIA_API_KEY_LLAMA3_70B=     # NVIDIA API key (70B model)
CLOUD_ADAPTER_API_KEY=         # Mistral API key
MISTRAL_MODEL=                 # Mistral model name
LOCAL_LLAMA_API_BASE_URL=      # Local Llama URL (optional)
LOCAL_LLAMA_MODEL_NAME=        # Local Llama model (optional)

πŸ“Š Performance

  • Email Analysis: < 3 seconds
  • Translation: < 2 seconds (cached: < 100ms)
  • OCR Processing: 5-10 seconds (depending on document size)
  • RAG Question Answering: 3-5 seconds
  • Calendar Availability Check: < 1 second
  • Auto-Reply Generation: < 3 seconds

🚧 Roadmap

Phase 1 (Current - Hackathon MVP)

  • βœ… Gmail integration
  • βœ… Email analysis & translation
  • βœ… Task detection
  • βœ… Auto-reply generation
  • βœ… Attachment processing
  • βœ… Calendar integration
  • βœ… RAG Q&A
  • βœ… Document classification

Phase 2 (Post-Hackathon)

  • Email drafting assistant
  • Bulk email processing
  • Advanced filters & rules
  • Email templates
  • Analytics dashboard
  • Mobile app (React Native)

Phase 3 (Future)

  • Multi-account support
  • Team collaboration features
  • Integration with Slack, Teams
  • Custom AI model training
  • Enterprise SSO
  • Advanced security features

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Guidelines

  • Follow the existing code style
  • Add tests for new features
  • Update documentation
  • Ensure all tests pass before submitting PR

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Sofrecom Tunisia for hosting the hackathon
  • Next.js Team for the amazing framework
  • FastAPI for the blazing-fast backend framework
  • Google for Gmail and Calendar APIs
  • NVIDIA and Mistral AI for powerful language models
  • OpenAI for inspiration and API design patterns
  • HuggingFace for embeddings and transformers
  • Tesseract OCR for text extraction capabilities

πŸ‘₯ Team

@ImenBenAmar @YomnaJL @ fakhfakheya @jerbi86

🌟 Star Us!

If you find this project useful, please consider giving it a ⭐ on GitHub!


Made with ❀️ for Sofrecom Tunisia Hackathon 2025

About

An intelligent email automation platform powered by AI that transforms how you manage, analyze, and respond to emails.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •