This project provides an email notification service using Node.js, Nodemailer, Bull for queueing jobs, and Redis for job persistence. The service sends device alerts via email and ensures that emails are retried in case of failures.
- Sends email notifications with device activity details.
- Checks if Internet COnnectivity is Present to push Email Out.
- Uses Bull for job queueing and retry mechanisms.
- Connects to a Redis server for job persistence.
- Gracefully handles application shutdown.
Before running this project, ensure you have the following installed:
- Node.js (v14.x or later)
- Redis server (v5.x or later)
- Git
-
Clone the Repository:
git clone https://github.com/faraz66/Email_Service.git cd Email_Service
-
Install Dependencies:
npm install
-
Configure Environment Variables:
Create a
.env
file in the root directory of the project and add your SMTP configuration and Redis configuration. For example:SMTP_HOST= SMTP_PORT= SMTP_USER= SMTP_PASS= REDIS_HOST=127.0.0.1 REDIS_PORT=6379
-
Run Redis Server:
Ensure your Redis server is running. You can start it using the following command:
redis-server
-
Run the Application:
node testscript.js
You can add emails to the queue by calling the addToQueue
function with the recipient email and device information. This will add a job to the Bull queue and handle retries if the email sending fails.
Example:
const { addToQueue } = require('./queues/emailQueue');
addToQueue('recipient@example.com', {
DeviceName: "Device-112",
DeviceId: "KT5138",
Action: "Power is Connected",
MacId: "00:1A:2B:3C:4D:5E",
TimeofActivity: new Date().toISOString()
});