This is a web application built with the MERN stack (MongoDB, Express, React, and Node.js) that allows users to register, log in, and send emails using their Gmail account. Upon registration, users must provide their Gmail email address and Gmail App Password. Once logged in, users can send emails using their Gmail account.
- User Registration & Login: Users can register by providing a Gmail email, a Gmail App Password, and a password for the app. After registration, users can log in using their credentials.
- Send Emails: Once logged in, users can send emails using their Gmail account.
- Token-based Authentication: JSON Web Tokens (JWT) are used to securely authenticate users.
- Validation: AJV (Another JSON Schema Validator) is used for input validation, ensuring data integrity.
- Docker Support: The app is containerized using Docker for easy setup and deployment.
- TypeScript Support: The backend is built using TypeScript for better type safety and code maintainability.
- Node.js: Server-side JavaScript runtime.
- Express.js: Web framework for Node.js.
- MongoDB: NoSQL database for storing user data.
- AJV: JSON Schema Validator used for validating user input.
- JWT (JSON Web Tokens): Used for secure user authentication.
- TypeScript: Type-safe JavaScript superset for better developer experience.
- Gmail SMTP: Users authenticate using Gmail App Passwords, and the app sends emails via Gmail SMTP servers.
- Next.js: React framework for building the user interface, including registration, login, and sending email.
- React: Library for building interactive user interfaces.
- dotenv: For managing environment variables securely.
- Docker: Containerization tool for running the application in isolated environments.
To run this application locally, ensure you have the following:
- Node.js: v20 or higher.
- MongoDB: Installed locally or a cloud-based MongoDB instance (e.g., MongoDB Atlas).
- Docker: Installed if you want to use the Docker setup.
- Gmail App Password: Each user needs to generate a Gmail App Password to send emails via their Gmail account.
Create a .env
file in the backend of the project and add the following environment variables:
# General
PORT=5000
MONGO_URI=<your_mongodb_connection_string>
JWT_SECRET=<your_jwt_secret>
-
Clone the repository:
git clone https://github.com/khalilhasan23/mail-sender.git
-
Install dependencies:
# Install backend dependencies cd backend npm install # Install frontend dependencies cd ../frontend npm install
-
Run MongoDB: Make sure MongoDB is running locally or provide a connection string to a MongoDB instance.
-
Build and run the Docker containers:
docker-compose up --build
-
Visit
http://localhost:3000
to access the application.
-
Register:
- Go to the registration page.
- Enter your Gmail email, Gmail App Password, and create a password for the app.
-
Login:
- Go to the login page and enter your email and password.
- A JWT token is generated upon successful login, which will be used for authentication in subsequent requests.
-
Send Email:
- After logging in, use the form to send an email by providing the recipient’s email, subject, and body.
In order to send emails using Gmail, users need to create a Gmail App Password.
Follow these steps to create an App Password:
- Go to your Google Account Security Settings.
- Scroll down to "Signing in to Google" and make sure 2-Step Verification is enabled.
- Once enabled, click on "App passwords".
- Select the app (Mail) and device (your custom name), then click "Generate".
- Use the generated App Password in the registration process.
User inputs are validated using AJV. Invalid data will result in validation errors, ensuring the app operates with correct and secure data.
- Login: After login, a JWT is created and stored in the frontend.
- Protected Routes: Users must have a valid token to access routes for sending emails.
docker-compose down