An intelligent email management system with AI-powered content generation, spam detection, and scheduled sending capabilities.
Features • Installation • Usage • Technologies • Contributing
- 🤖 AI Email Generation: Automatically generate professional emails based on prompts using advanced AI
- 🛡️ Spam Detection: Naive Bayes classifier to detect and filter spam emails
- ⏰ Scheduled Sending: Schedule emails to be sent at specific times with APScheduler
- 🔐 Google OAuth: Secure authentication via Google OAuth 2.0
- 📧 Gmail Integration: Send emails directly through Gmail API
- 📱 Responsive Design: Modern, mobile-friendly UI with Font Awesome icons
SpamGuardMailer/
├── app.py # Main application entry point
├── config/
│ ├── __init__.py
│ ├── logging_config.py # Logging configuration
│ ├── models.py # Database models (SQLAlchemy)
│ └── mysql.py # MySQL configuration
├── routes/
│ ├── __init__.py
│ ├── MailerSender.py # Email sending logic
│ ├── MailerTester.py # Spam detection logic
│ ├── word_freq.json # Word frequencies for classifier
│ └── class_freq.json # Class frequencies for classifier
├── static/
│ ├── Css/
│ │ ├── base.css # Base styles
│ │ ├── homepage.css # Homepage styles
│ │ ├── send_email.css # Email form styles
│ │ ├── preview_email.css # Preview styles
│ │ ├── rapport.css # Rapport styles
│ │ └── schedule_email.css # Schedule form styles
│ └── JS/
│ └── base.js # JavaScript functionality
├── templates/
│ ├── base.html # Base template
│ ├── homepage.html # Landing page
│ ├── send_email.html # Email generation form
│ ├── preview_email.html # Email preview
│ ├── schedule_email.html # Schedule form
│ ├── successful.html # Success page
│ ├── rapport.html # Spam detection results
│ ├── detect_spam.html # Spam detection form
│ └── error.html # Error pages
├── .env # Environment variables (not committed)
├── requirements.txt # Python dependencies
└── README.md # This file
Before you begin, ensure you have the following installed:
- Python 3.8+
- MySQL/MariaDB database
- Google Cloud Console project with OAuth 2.0 credentials
git clone https://github.com/YSN-B13/SpamGuardMailer.git
cd SpamGuardMailer# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root with the following variables:
# Flask Configuration
FLASK_SECRET_KEY=your_secret_key_here
# Google OAuth
GOOGLE_OAUTH_CLIENT_ID=your_google_client_id
GOOGLE_OAUTH_CLIENT_SECRET=your_google_client_secret
OAUTHLIB_INSECURE_TRANSPORT=1 # Only for development
# AI API Key
GEMINI_API_KEY=your_gemini_api_key
# MySQL Database
MYSQL_USER=your_mysql_user
MYSQL_PASSWORD=your_mysql_password
MYSQL_DB=your_database_name
MYSQL_HOST=localhost- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable Gmail API:
- Navigate to APIs & Services → Library
- Search for "Gmail API" and enable it
- Create OAuth 2.0 Credentials:
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
- Configure consent screen:
- User Type: External
- Scopes:
openid,email,profile,https://www.googleapis.com/auth/gmail.send
- Add Authorized redirect URI:
http://127.0.0.1:5000/login/google/authorized
- Copy Client ID and Client Secret to your
.envfile
python app.pyThe application will be available at http://127.0.0.1:5000
- Navigate to the homepage
- Click "Send Email" or "Generate Email"
- Enter email details or provide a prompt for AI generation
- Preview the email
- Send immediately or schedule for later
- Navigate to "Detect Spam"
- Paste email content
- Click "Analyze"
- View spam probability and classification results
- Create an email as usual
- Select "Schedule Email"
- Choose date and time
- Confirm scheduling
⚠️ Important Security Notes:
- Never commit
.envfile to version control - Store OAuth tokens encrypted in production
- Use HTTPS in production (Google requires it for OAuth)
- Set
offline=Truein Google blueprint to get refresh tokens - Implement rate limiting for API endpoints
- Validate and sanitize all user inputs
- Use environment-specific configurations
| Category | Technologies |
|---|---|
| Backend | Flask, Flask-Dance, Flask-SQLAlchemy |
| Database | MySQL/MariaDB with SQLAlchemy ORM |
| Authentication | Google OAuth 2.0 |
| Gmail API | |
| Scheduling | APScheduler |
| Frontend | HTML5, CSS3, JavaScript, Font Awesome |
| AI | Gemini API (for email generation) |
| Machine Learning | Naive Bayes (for spam detection) |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/AmazingFeature
- Commit your changes
git commit -m 'Add some AmazingFeature' - Push to the branch
git push origin feature/AmazingFeature
- Open a Pull Request
- Follow PEP 8 style guide for Python code
- Write descriptive commit messages
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
Yassine Moutawakkil
- GitHub: @YSN-B13
- Email: yassinemoutawakkil2004@gmail.com
- Google OAuth for authentication
- Flask community for excellent documentation
- All contributors who help improve this project
Made with ❤️ by Yassine Moutawakkil
⭐ Star this repository if you find it helpful!