A Spring Boot web application designed to detect and analyze spam emails using rule-based detection methods. The system provides a comprehensive analysis with spam scoring, keyword detection, and PDF report generation.
The Spam Email Detection and Analysis System helps users identify whether an email is Spam or Not Spam by analyzing email content and subject lines using predefined rules. The application stores analysis history and generates detailed PDF reports.
- π§ Email Analysis: Analyze email subject and content for spam characteristics
- π User Authentication: Secure login and registration with password encryption (BCrypt)
- π Dashboard: Visual statistics with pie and bar charts
- π History Management: View and search all email analyses
- π PDF Report Generation: Download detailed analysis reports
- π₯ Role-Based Access Control: Separate dashboards for Admin and User roles
- π― Spam Keywords Detection: Identify suspicious keywords
- π Spam Score Calculation: Quantifiable spam probability (0-100%)
- π€ Text Pattern Analysis: Detect excessive caps, punctuation, URLs
- π§ Email Count Detection: Identify suspicious email addresses
- Framework: Spring Boot 3.2.0
- Security: Spring Security + BCrypt
- ORM: Spring Data JPA
- Database: MySQL 8.0
- PDF Generation: iText 5.5.13
- Template Engine: Thymeleaf
- Styling: Bootstrap 5.3
- Charts: Chart.js 4.4
- Responsive Design: Mobile-friendly UI
- MySQL 8.0+
- Tables: users, email_analysis
spam-email-detection/
βββ src/
β βββ main/
β β βββ java/com/spamdetection/
β β β βββ controller/
β β β β βββ AuthController.java
β β β β βββ DashboardController.java
β β β β βββ EmailAnalysisController.java
β β β β βββ ReportController.java
β β β βββ service/
β β β β βββ UserService.java
β β β β βββ EmailAnalysisService.java
β β β β βββ SpamDetectionService.java
β β β β βββ PDFReportService.java
β β β βββ entity/
β β β β βββ User.java
β β β β βββ EmailAnalysis.java
β β β βββ repository/
β β β β βββ UserRepository.java
β β β β βββ EmailAnalysisRepository.java
β β β βββ config/
β β β β βββ SecurityConfig.java
β β β β βββ CustomUserDetailsService.java
β β β βββ dto/
β β β β βββ EmailAnalysisRequest.java
β β β β βββ EmailAnalysisResponse.java
β β β β βββ UserRegistrationRequest.java
β β β βββ SpamEmailDetectionApplication.java
β β βββ resources/
β β βββ templates/
β β β βββ login.html
β β β βββ register.html
β β β βββ dashboard-user.html
β β β βββ dashboard-admin.html
β β β βββ analyze.html
β β β βββ history.html
β β β βββ analysis-detail.html
β β βββ static/
β β β βββ css/
β β β βββ js/
β β βββ application.properties
βββ pom.xml
βββ README.md
- Java 17 or higher
- Maven 3.6+
- MySQL 8.0+
-
Create Database
CREATE DATABASE spam_detection_db;
-
Configure Database Connection
Edit
src/main/resources/application.properties:spring.datasource.url=jdbc:mysql://localhost:3306/spam_detection_db spring.datasource.username=root spring.datasource.password=your_password
-
Build the Project
mvn clean install
-
Run the Application
mvn spring-boot:run
Or using Java:
java -jar target/spam-email-detection-1.0.0.jar
-
Access the Application
- Open browser and navigate to:
http://localhost:8080
- Open browser and navigate to:
-
Create Admin User
- Register a user with username and email
- Manually update the role in database:
UPDATE users SET role = 'ROLE_ADMIN' WHERE username = 'admin_username';
-
Login
- Use your credentials to login
- Go to "Analyze Email"
- Paste email subject and content
- Click "Analyze Email"
- View results with spam score and detected keywords
- Access "History" to view all analyses
- Download PDF reports for any analysis
- View system-wide statistics on the admin dashboard
- See pie charts and bar charts of spam distribution
- Access all user analyses
- View and analyze emails same as regular users
The system uses rule-based spam detection with the following factors:
- Suspicious phrases: "free", "winner", "urgent", "click here", etc.
- Financial terms: "wire transfer", "bank account", "credit card"
- Phishing indicators: "verify account", "confirm identity"
- Excessive Punctuation: Multiple exclamation marks or question marks (>5)
- Excessive Caps: Text with >70% uppercase letters
- URL Detection: Presence of HTTP/HTTPS URLs
- Email Count: Multiple email addresses in content
- Each spam indicator adds points (0-100 scale)
- Final score β₯ 50% classified as SPAM
- Score < 50% classified as NOT SPAM
GET /login- Login pagePOST /login- Submit login credentialsGET /register- Registration pagePOST /register- Create new account
GET /dashboard- View dashboard (user/admin based on role)
GET /analyze- Analyze email formPOST /analyze- Submit email for analysisGET /analysis/{id}- View analysis details
GET /history- View all user analyses
GET /report/pdf/{id}- Download PDF report
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(100) NOT NULL
);CREATE TABLE email_analysis (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT NOT NULL,
subject VARCHAR(500) NOT NULL,
content LONGTEXT NOT NULL,
result VARCHAR(50) NOT NULL,
spam_score DOUBLE NOT NULL,
keywords_detected TEXT,
created_at DATETIME NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);- β BCrypt password hashing
- β Spring Security authentication
- β Role-based access control
- β Session management
- β CSRF protection
- β Secure password storage
- β User authorization checks
- Analysis results generated within 2 seconds
- Optimized database queries with JPA
- Lazy loading for large datasets
- Efficient spam detection algorithm
β
Users can analyze email content
β
System classifies Spam/Not Spam
β
Results stored in database
β
Dashboard displays statistics
β
PDF reports can be generated
β
Login and role-based access work correctly
- Machine learning-based spam detection
- Advanced user search filters
- Batch email analysis
- Email forwarding integration
- Real-time notifications
- API for third-party integrations
Q: Database connection error
- A: Verify MySQL is running and credentials in
application.propertiesare correct
Q: Port 8080 already in use
- A: Change port in
application.properties:server.port=8081
Q: Tables not created
- A: Ensure
spring.jpa.hibernate.ddl-auto=updateis set inapplication.properties
This project is provided as-is for educational and development purposes.
Developed as per the Spam Email Detection and Analysis System Product Requirements Document.
Last Updated: 2024-01-01
Version: 1.0.0