SafeMail-AI is an intelligent web application designed to detect phishing and scam emails using Natural Language Processing (NLP) and Machine Learning. Created for Winter Code 5.0, this project bridges the gap between theoretical data science and practical, deployable software.
- 🧠 ML-Powered Classification: Utilizes a Logistic Regression model paired with a TF-IDF vectorizer to accurately classify emails as safe or suspicious.
- 🔍 Heuristic URL Analysis: Automatically extracts and evaluates embedded links to detect shortened domains (e.g.,
bit.ly) and highly suspicious Top-Level Domains (TLDs) (e.g.,.xyz,.tk). - 🚨 Threat Highlighting: Parses email content to dynamically highlight known scam triggers and urgent keywords (e.g., "verify", "password", "bank") in the UI.
- 🚥 Dynamic Risk Scoring: Adjusts the confidence level and risk assessment (Low, Medium, High) based on a combination of ML probabilities and deterministic URL analysis.
- ☁️ Production-Ready Backend: Built with Flask and Gunicorn, featuring environment-based configurations (
developmentvs.production) for seamless PaaS deployment.
- Language: Python 3.11.4
- Backend: Flask, Gunicorn
- Machine Learning: Scikit-Learn, Pandas, NumPy
- Frontend: HTML/CSS (Jinja2 Templates, MarkupSafe)
- Deployment: Ready for Render, Railway, or Heroku (includes
Procfileandruntime.txt)
Ensure you have Python 3.11+ installed.
-
Clone the repository:
git clone [https://github.com/lipikaparida-web/SafeMail-AI.git](https://github.com/lipikaparida-web/SafeMail-AI.git) cd SafeMail-AI -
Set up a virtual environment: python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies: pip install -r requirements.txt Set FLASK_DEBUG=1 in your .env for local development.
-
Environment Variables: Copy the sample environment file and adjust if necessary: cp .env.sample .env
-
Train the Model (Optional): If you want to retrain the ML model with your own dataset, add your data to phishing.csv and run: python train_model.py This will generate the required phishing_model.pkl and vectorizer.pkl files in the model/ directory.
-
Run the Application: python app.py
Access the app locally at http://127.0.0.1:5000
SafeMail-AI is structured for immediate deployment on modern PaaS providers.
Push your code to GitHub.
Connect the repository to your preferred platform (Render, Railway, etc.).
The platform will automatically detect the Procfile (web: gunicorn app:app) and runtime.txt to provision the environment.
Ensure APP_ENV is set to production in your platform's environment variables.
The core detection engine is built on a Logistic Regression classifier.
Feature Extraction: TfidfVectorizer (capped at 3000 max features, English stop words removed).
Training Data: A curated CSV dataset of labeled phishing and safe emails.
Evaluation: Standard accuracy scoring using an 80/20 train-test split.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.