A professional email analysis and quality assessment service with a modern web interface, API access, and production-ready architecture.
- Email Content Analysis: Comprehensive grammar checking, style analysis, and quality scoring
- User Authentication: Secure login/registration with email/mobile OTP verification
- API Access: RESTful API for programmatic access with rate limiting
- Production Ready: Scalable architecture with proper separation of concerns
- Modern Web UI: Responsive design with Bootstrap 5 and custom styling
- Real-time Results: Instant feedback on email quality and improvement suggestions
The application follows a production-ready architecture with:
- Application Factory Pattern: Modular Flask application creation
- Blueprint Structure: Organized routes and views
- Service Layer: Business logic separation
- Model Layer: Database models with relationships
- Configuration Management: Environment-based configuration
- Rate Limiting: API usage tracking and limits
- Logging: Comprehensive logging system
EmailAuditor/
βββ app/ # Main application package
β βββ __init__.py # Application factory
β βββ models/ # Database models
β β βββ __init__.py
β β βββ user.py # User model
β β βββ otp.py # OTP model
β β βββ audit.py # Email audit model
β βββ services/ # Business logic services
β β βββ __init__.py
β β βββ email_service.py # Email/OTP service
β β βββ audit_service.py # Email auditing service
β β βββ email_parser.py # Email parsing
β β βββ rules_engine.py # Rules evaluation
β β βββ audit_report.py # Report generation
β β βββ rules_impl.py # Rule implementations
β βββ web/ # Web interface routes
β β βββ __init__.py
β β βββ routes.py
β βββ api/ # API routes
β β βββ __init__.py
β β βββ routes.py
β βββ utils/ # Utility functions
β β βββ __init__.py
β β βββ rate_limiter.py
β βββ templates/ # HTML templates
β βββ static/ # Static files (CSS, JS)
βββ config/ # Configuration management
β βββ __init__.py
β βββ config.py
βββ tests/ # Test suite
βββ migrations/ # Database migrations
βββ scripts/ # Utility scripts
βββ logs/ # Application logs
βββ uploads/ # File uploads
βββ wsgi.py # WSGI entry point
βββ manage.py # Management commands
βββ requirements.txt # Python dependencies
βββ Dockerfile # Production Docker image
βββ docker-compose.yml # Multi-service deployment
βββ env.example # Environment variables template
βββ README.md # This file
- Python 3.11 or higher
- pip (Python package installer)
- Git
-
Clone the repository
git clone <repository-url> cd EmailAuditor
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp env.example .env # Edit .env file with your configuration -
Initialize database
python manage_db.py init
-
Run the application
python wsgi.py
-
Access the application
- Web UI: http://localhost:5000
- API Documentation: http://localhost:5000/docs
Create a .env file based on env.example:
# Flask Configuration
FLASK_ENV=development
SECRET_KEY=your-secret-key-change-this-in-production
# Database Configuration
DATABASE_URL=sqlite:///email_auditor.db
# For production: postgresql://user:password@localhost/email_auditor
# Email Configuration (for OTP)
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_USE_TLS=true
# Rate Limiting
FREE_TIER_DAILY_LIMIT=5
PREMIUM_TIER_DAILY_LIMIT=100
# Security
SESSION_COOKIE_SECURE=false
SESSION_COOKIE_HTTPONLY=true
SESSION_COOKIE_SAMESITE=Lax
# Logging
LOG_LEVEL=INFO
LOG_FILE=logs/app.logFor OTP functionality, configure SMTP settings:
-
Gmail Setup:
- Enable 2-factor authentication
- Generate an App Password
- Use the App Password in
SMTP_PASSWORD
-
Other Email Providers:
- Update
SMTP_SERVERandSMTP_PORTaccordingly - Use appropriate credentials
- Update
-
Build and run with Docker Compose
docker-compose up -d
-
Access the application
- Web UI: http://localhost:5000
- API: http://localhost:5000/api
-
Set production environment
export FLASK_ENV=production export SECRET_KEY=your-secure-secret-key
-
Use Gunicorn
pip install gunicorn gunicorn -w 4 -b 0.0.0.0:5000 wsgi:app
-
Set up reverse proxy (nginx recommended)
-
Configure SSL/TLS for secure communication
All API requests require an API key in the header:
X-API-Key: your_api_key_here
1. Audit Email
POST /api/audit
Content-Type: multipart/form-data
X-API-Key: your_api_key
file: [.eml file]2. Check Usage
GET /api/usage
X-API-Key: your_api_key3. Manage API Key
GET /api/key
POST /api/keyPython:
import requests
api_key = "your_api_key_here"
url = "http://localhost:5000/api/audit"
with open("email.eml", "rb") as f:
files = {"file": f}
headers = {"X-API-Key": api_key}
response = requests.post(url, files=files, headers=headers)
result = response.json()
print(f"Email Score: {result['score']}")cURL:
curl -X POST \
-H "X-API-Key: your_api_key_here" \
-F "file=@email.eml" \
http://localhost:5000/api/auditpytestpytest --cov=app tests/The application includes a database management script for various operations:
# Initialize database tables
python manage_db.py init
# Check database status
python manage_db.py check
# Reset database (WARNING: deletes all data)
python manage_db.py reset
# Create admin user
python manage_db.py create-adminIf you encounter database errors during deployment (like "table already exists"), the application now handles this gracefully. The database initialization will:
- Check if tables already exist
- Skip table creation if they exist
- Create tables only if they're missing
- Log the status for debugging
For Render deployment specifically:
- The application automatically handles existing database tables
- No manual database reset is required between deployments
- Database state is preserved across deployments
python manage.py test-emailApplication logs are stored in logs/app.log with rotation.
GET /pingResponse:
{
"message": "pong",
"timestamp": "2024-01-15T10:30:00.000Z"
}GET /healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"version": "2.0.0",
"services": {
"database": "connected",
"email_service": "available",
"audit_service": "available"
},
"uptime": "running"
}API Health Check:
GET /api/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"version": "2.0.0",
"environment": "production",
"services": {
"database": {
"status": "connected",
"users": 25,
"audits": 150
},
"email_service": "available",
"audit_service": "available",
"rate_limiter": "available"
},
"limits": {
"free_tier_daily": 5,
"premium_tier_daily": 100
}
}- API Key Authentication: Secure API access
- Rate Limiting: Prevents abuse
- Input Validation: File type and size validation
- SQL Injection Protection: SQLAlchemy ORM
- XSS Protection: Template escaping
- CSRF Protection: Built-in Flask protection
- Database: Supports PostgreSQL for production
- Caching: Redis integration ready
- Background Tasks: Celery integration ready
- Load Balancing: Gunicorn with multiple workers
- Horizontal Scaling: Stateless application design
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.
For support and questions:
- Create an issue in the repository
- Check the API documentation at
/docs - Review the configuration examples
- Complete code refactoring with proper architecture
- Application factory pattern
- Service layer implementation
- Production deployment support
- Comprehensive testing setup
- Monitoring and logging
- Security enhancements