This repository houses the email service component of the MLOGS application. The mlogs email service is a dedicated microservice for handling email-related functionalities such as account verification, password reset, and notifications. Built as a standalone service, it operates independently from the core mlogs backend, ensuring scalability and separation of concerns.
To get a local copy up and running, please follow these simple steps.
Here is what you need to be able to run MLOGS.
- Node.js (Version: >=20.x)
- Redis
- NPM
Before setting up this email service, ensure the main backend is up and running with Redis properly configured. This service relies on Redis, using BullMQ to manage and queue emails.
Make sure Redis is set up correctly so it can communicate with this service to handle email notifications and job processing.
-
Clone the repo into a public GitHub repository (or fork https://github.com/dev-mayanktiwari/mlogs-final).
git clone https://github.com/dev-mayanktiwari/mlogs-email-service
If you are on Windows, run the following command on
gitbash
with admin privileges:
>git clone -c core.symlinks=true https://github.com/dev-mayanktiwari/mlogs-email-service
-
Go to the project folder
cd mlogs-email-service
-
Install packages with npm
npm install
-
Set up your
.env
file- Duplicate
.env.example
to.env
- Duplicate
-
Setup Node If your Node version does not meet the project's requirements as instructed by the docs, "nvm" (Node Version Manager) allows using Node at the version required by the project:
nvm use
You first might need to install the specific version and then use it:
nvm install && nvm use
You can install nvm from here.
-
Redis Setup
To enable Redis functionality in the
mlogs
application, you need to configure Redis. You can set up Redis either locally or by using a cloud-based service.Redis Cloud (Cloud-based)
-
Choose a Redis Cloud Provider
- Pick a Redis cloud provider from the following options:
- Redis Labs
- Upstash
- Aiven
-
Create an Account and Provision a Redis Instance
- Sign up for an account with your chosen provider.
- Create a new Redis instance through their dashboard.
- After the instance is created, you will be provided with connection details, including:
- Host (Redis endpoint)
- Port (usually
6379
or a custom port) - Password (if authentication is enabled)
-
Get the Redis Connection Details
- You will need the following information from your Redis provider:
- Host: Your Redis instance hostname (e.g.,
your-redis-hostname
). - Port: Typically
6379
. - Password: The password (if set) for connecting to the Redis instance.
- Host: Your Redis instance hostname (e.g.,
- You will need the following information from your Redis provider:
-
Add Redis Connection Details to Your
.env
File-
In your
.env
file, configure the Redis connection as follows:REDIS_HOST=your-redis-hostname REDIS_PORT=6379 REDIS_PASSWORD=your-redis-password (if applicable)
-
-
-
Nodemailer Setup
To send notification emails, you need to configure an email account in the .env file, along with necessary credentials. It’s recommended to use app passwords instead of your main email password for security.
If you’re using Gmail, you can follow this guide to generate an app password. For other email providers, check their settings for SMTP configuration and security best practices.
To send failed job notifications to the admin (optional), specify an admin email address in the .env file. You can use the same email account for both sending notifications and receiving admin alerts.
MAILER_HOST=smtp.gmail.com #GMAIL Example MAILER_SERVICE=gmail #GMAIL Example MAILER_PORT=587 [email protected] EMAIL_PASS=youremailpassword [email protected]
-
Log Database Setup (Optional)
To enable logging in the
mlogs
application, you can set up a MongoDB database to store logs. Follow the steps below to configure MongoDB either through a managed service (MongoDB Atlas) or locally using Docker.Setup using MongoDB Atlas (Cloud-based)
-
Create an Account on MongoDB Atlas
- Go to MongoDB Atlas and sign up for a free account.
-
Create a New Cluster
- After logging in, create a new cluster. Select your preferred cloud provider and region.
-
Create a MongoDB User
- Go to the "Database Access" section, and create a user with a username and password. Remember to keep these credentials safe.
-
Get the Connection String
- Replace
<username>
and<password>
in the connection string with the MongoDB user credentials you created. - Go to the "Connect" section, select "Connect your application," and copy the connection string.
- Replace
-
Add the Connection String to Your Environment Variables
- In your
.env
file, add the connection string as follows:
MONGO_URL="mongodb+srv://yourusername:[email protected]/logs?retryWrites=true&w=majority"
- In your
-
Verify the Connection (Optional)
- Run a quick connection test in your application to ensure MongoDB is correctly set up and accessible.
-
-
Running the application
Once you've completed the setup, you can start the email service by running(make sure you have nodemon installed):
npm run dev
-
Run Redis container (Optional, for email service)
Use the following docker command to run a docker container:
docker run -d --name mlogs_redis -p 6379:6379 redis redis-server --requirepass mysecretpassword
Update the .env file with the connection details:
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD=mysecretpassword
-
Nodemailer Setup
To send notification emails, you need to configure an email account in the .env file, along with necessary credentials. It’s recommended to use app passwords instead of your main email password for security.
If you’re using Gmail, you can follow this guide to generate an app password. For other email providers, check their settings for SMTP configuration and security best practices.
To send failed job notifications to the admin (optional), specify an admin email address in the .env file. You can use the same email account for both sending notifications and receiving admin alerts.
MAILER_HOST=smtp.gmail.com #GMAIL Example MAILER_SERVICE=gmail #GMAIL Example MAILER_PORT=587 [email protected] EMAIL_PASS=youremailpassword [email protected]
-
Run MONGODB Container (Optional)
Start a MONGODB container using docker, require for logging:
docker run -d --name mlogs -p 27017:27017 mongo
Update the .env file with the connection string:
MONGO_URL="mongodb://localhost:27017"
-
Build the image
In the root directory run the following command to build the image:
docker build -t mlogs-email-service .
-
Start the container:
Run the image by running the following command and passing the env file:
docker run -d --name mlogs_backend_container --env-file .env -p 3000:3000 mlogs-email-service
Please see our contributing guide.
This project is licensed under the MIT License - see the LICENSE file for details.