A Java-based mail and user session management project developed using Java Servlets, JDBC, MySQL, and Jakarta Mail API.
The project demonstrates authentication handling, session management, cookie tracking, database integration, and email functionality in Java web applications.
- User login authentication
- Session management using Servlets
- Cookie-based user tracking
- Dashboard access handling
- JDBC-based MySQL database connectivity
- Mail sending functionality
- Jakarta Mail API integration
- Servlet-based architecture
- Basic user management workflow
- Java
- Java Servlets
- JDBC
- MySQL
- Jakarta Mail API
- Jakarta Activation API
- MySQL Connector/J
- Apache Tomcat Server
- Servlet API
- Session Management
- Cookie Handling
JavaMailProject/
├── CookieDashboard.java
├── CookieServlet.java
├── DBConnection.java
├── DashboardServlet.java
├── LoginServlet.java
├── SessionServlet.java
├── mailclient/
│ ├── DBConnection.java
│ └── MailClientWithDrawer.java
├── lib/
│ ├── jakarta.activation-2.0.1.jar
│ ├── jakarta.mail-2.0.2.jar
│ └── mysql-connector-java-8.0.21.jar
└── README.md
Handles user login and database validation using:
LoginServlet.java
Features:
- Username/password validation
- Database verification
- Session creation after login
Manages active user sessions using:
SessionServlet.java
Features:
- Session creation
- Session tracking
- User authentication persistence
Implements cookie-based tracking using:
CookieServlet.java
CookieDashboard.java
Features:
- Cookie storage
- Cookie retrieval
- User tracking
Provides dashboard access after successful authentication using:
DashboardServlet.java
Implements Java mail functionality using:
MailClientWithDrawer.java
Features:
- Email sending
- Mail configuration
- SMTP-based communication
- Jakarta Mail integration
Before running the project, install:
- JDK 8 or higher
- Apache Tomcat Server
- MySQL Server
- Java Servlet API
- Jakarta Mail API
- MySQL Connector/J
git clone https://github.com/code-with-nc/JavaMailProject.git
cd JavaMailProjectgit clone git@github.com:code-with-nc/JavaMailProject.git
cd JavaMailProjectVerify installation:
java -version
javac -version
mysql --versionLogin to MySQL:
mysql -u root -pCreate database:
CREATE DATABASE javamailproject;Use database:
USE javamailproject;Create sample user table:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(100),
password VARCHAR(100)
);Insert sample user:
INSERT INTO users(username, password)
VALUES ('admin', 'admin123');Update database credentials inside:
DBConnection.java
Example:
String url = "jdbc:mysql://localhost:3306/javamailproject";
String username = "root";
String password = "your_mysql_password";Add all JAR files from:
lib/
to your project build path.
Required JARs:
jakarta.activation-2.0.1.jar
jakarta.mail-2.0.2.jar
mysql-connector-java-8.0.21.jar
Download Apache Tomcat:
Copy project files into:
apache-tomcat/webapps/
OR import the project into:
- Eclipse IDE
- IntelliJ IDEA
- NetBeans
and configure Tomcat server.
Example using terminal:
javac *.javaLinux:
cd apache-tomcat/bin
./startup.shWindows:
startup.batExample:
http://localhost:8080/JavaMailProject
For mail functionality, configure SMTP credentials inside:
MailClientWithDrawer.java
Example:
String host = "smtp.gmail.com";
String from = "your_email@gmail.com";
String password = "your_app_password";- Session Management
- Cookie Handling
- Authentication Flow
- Database Connectivity
- SMTP Mail Handling
- Servlet Lifecycle
- JDBC Operations
- Basic Web Security Concepts
After completing this project, learners will be able to:
- Build Java Servlet-based web applications
- Implement user authentication systems
- Manage user sessions and cookies
- Connect Java applications with MySQL using JDBC
- Configure and use Jakarta Mail API
- Deploy Java web applications on Apache Tomcat
- Understand servlet request-response workflow
- Handle database-driven login systems
- Understand basic Java web security concepts
- Convert project into Maven structure
- Add frontend UI pages
- Add password hashing
- Add role-based authentication
- Add email verification workflow
- Improve project structure using
src/main/java - Add REST API support
- Add Docker deployment support
- Add JWT-based authentication
Verify:
- MySQL server is running
- JDBC URL is correct
- username/password are valid
Run Tomcat on another port:
8081
Update:
conf/server.xml
inside Tomcat.
Check:
- servlet mapping
- Tomcat deployment
- compiled
.classfiles - project structure
Use:
- Gmail App Password
- SMTP enabled account
instead of normal Gmail password.
This project is intended for:
- educational purposes
- Java web development learning
- servlet practice
- secure coding understanding
Do not deploy with default credentials or insecure configurations in production environments.
Narayani
GitHub: https://github.com/code-with-nc