A Node.js application built with Express.js that implements a clean MVC (Model-View-Controller) architecture for handling email functionality. This project demonstrates best practices in organizing a Node.js application with proper separation of concerns.
- Clean MVC architecture
- Email sending functionality using Nodemailer
- EJS templating engine for views
- Environment variable configuration
- RESTful API endpoints
- CORS support
- Static file serving
Before you begin, ensure you have the following installed:
- Node.js (v12 or higher)
- npm (Node Package Manager)
- Clone the repository:
git clone https://github.com/CodeRafay/nodemailer-mvc-app.git
cd expressjs_mvc- Install dependencies:
npm install- Create a
.envfile in the root directory and add your email configuration:
PORT=3000
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-specific-passwordexpressjs_mvc/
├── config/ # Configuration files
├── controllers/ # Route controllers
├── routes/ # Route definitions
├── views/ # EJS templates
├── app.js # Main application file
├── index.js # Application entry point
└── package.json # Project dependencies
- Start the server:
npm test- Access the application:
- Web Interface: http://localhost:3000
- API Endpoint: http://localhost:3000/api/email
POST /api/email/send- Send an email- Request body:
{ "to": "recipient@example.com", "subject": "Email Subject", "text": "Email content" }
- Request body:
- express: Web framework
- nodemailer: Email sending functionality
- ejs: Template engine
- dotenv: Environment variable management
- cors: Cross-origin resource sharing
- Fork the repository
- Create your 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
Rafay Adeel
If you encounter any issues or have questions, please open an issue in the GitHub repository.