-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config mail service and rabbitmq docker
- Loading branch information
1 parent
23c29a0
commit 5842feb
Showing
7 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
management.path_prefix = /rmq |