Skip to content

Commit

Permalink
config mail service and rabbitmq docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Duc-Khai committed Dec 9, 2023
1 parent 23c29a0 commit 5842feb
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 25 deletions.
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ services:
volumes:
- ./airchecker/grafana-storage:/var/lib/grafana

rabbitmq:
image: rabbitmq:3.11-management
container_name: rabbitmq_air_checker
environment:
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: admin
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ./airchecker/rabbitmq:/var/lib/rabbitmq
- ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
networks:
- node-network

networks:
node-network:
driver: bridge
7 changes: 7 additions & 0 deletions email-service/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sendMail = require("./transporter");

const mailList = ["nguyenduckhai8101@gmail.com", "19521658@gm.uit.edu.vn"];

(async () => {
await sendMail(mailList);
})();
16 changes: 9 additions & 7 deletions email-service/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"amqp": "amqp://localhost",
"queue": "nodemailer-amqp",
"amqp": "amqp://localhost",
"queue": "nodemailer-amqp",

"server": {
"port": 12345,
"host": "localhost"
}
}
"smtp_server": {
"port": 465,
"host": "smtp.gmail.com",
"username": "kainguyen.business@gmail.com",
"password": "zrsc qmoy xozd aror"
}
}
36 changes: 18 additions & 18 deletions email-service/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "email-service",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"smtp": "nodemon smtp_server.js",
"subscriber": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"amqplib": "^0.10.3",
"nodemailer": "^6.9.7",
"nodemon": "^3.0.2",
"smtp-server": "^3.13.0",
"winston": "^3.11.0"
}
"name": "email-service",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"smtp": "nodemon smtp_server.js",
"app": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"amqplib": "^0.10.3",
"nodemailer": "^6.9.7",
"nodemon": "^3.0.2",
"smtp-server": "^3.13.0",
"winston": "^3.11.0"
}
}
43 changes: 43 additions & 0 deletions email-service/transporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const nodemailer = require("nodemailer");
const config = require("./config.json");
const logger = require("./logger");

const transporter = nodemailer.createTransport(
{
host: config.smtp_server.host,
port: config.smtp_server.port,
secure: true,
auth: {
user: config.smtp_server.username,
pass: config.smtp_server.password,
},
},
{
from: `"AQI Alert ⚠️" ${config.smtp_server.username}`,
}
);

const sendMail = async (mailList) => {
try {
// send mail with defined transport object
const info = await transporter.sendMail({
to: mailList, // list of receivers
subject: "AQI Level Alert", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
});

logger.info(`Message sent: ${info.messageId}`);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

//
// NOTE: You can go to https://forwardemail.net/my-account/emails to see your email delivery status and preview
// Or you can use the "preview-email" npm package to preview emails locally in browsers and iOS Simulator
// <https://github.com/forwardemail/preview-email>
//
} catch (error) {
logger.error(`Error when send email to [${to}]: ${error}`);
}
};

module.exports = sendMail;
15 changes: 15 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ upstream dashboard {
server dashboard_air_checker:3002;
}

upstream rabbitmq {
server rabbitmq_air_checker:15672 fail_timeout=0;
}

server {
listen 443 ssl;
ssl_certificate /ssl/fullchain.pem;
Expand Down Expand Up @@ -99,6 +103,17 @@ server {
proxy_http_version 1.1;
proxy_pass http://portainer/api/websocket/;
}

location /rmq {
proxy_pass http://rabbitmq;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_intercept_errors on;
proxy_buffering off;
proxy_redirect off;
}
}

server {
Expand Down
1 change: 1 addition & 0 deletions rabbitmq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
management.path_prefix = /rmq

0 comments on commit 5842feb

Please sign in to comment.