diff --git a/index.js b/index.mjs similarity index 71% rename from index.js rename to index.mjs index 9a5ce99..443d7ba 100644 --- a/index.js +++ b/index.mjs @@ -8,7 +8,7 @@ import dotenv from 'dotenv' dotenv.config() const app = express() -const queue = process.env.queueName +const queueName = process.env.queueName const senderEmail = "michael.pandu@ti.ukdw.ac.id" // const mailTransporter = nodemailer.createTransport({ // service: 'gmail', @@ -30,21 +30,21 @@ app.get('/', (_req, res) => { res.status.send(200).send("Amigo Receipt Sender Service Homepage!") }) -// amqp.connect('amqp://192.168.100.14' ).then(async conn=> { -// const ch = await conn.createChannel() -// const queue = ch.assertQueue(queueName, { durable: true }) -// if (queue) { -// queue.then(() => { -// return ch.consume(queueName, async (msg) => { -// var messageBody = msg.content.toJSON() -// console.log(`[*] Message Received! email : ${message.email} and pesan : `) -// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda") -// }, { noAck: true }) -// }).then(() => { -// console.log('* Waiting for messages from queue ' + queueName) -// }) -// } -// }).catch(console.warn) +amqp.connect('amqp://localhost' ).then(async conn=> { + const ch = await conn.createChannel() + const queue = ch.assertQueue(queueName, { durable: true }) + if (queue) { + queue.then(() => { + return ch.consume(queueName, async (msg) => { + var messageBody = JSON.parse(msg.content.toString()) + console.log(`[*] Message Received! email : ${messageBody.email} and pesan : ${messageBody.html}`) + // sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda") + }, { noAck: true }) + }).then(() => { + console.log('* Waiting for messages from queue ' + queueName) + }) + } +}).catch(console.warn) function sendReceipt(recepientEmail, receipt) { var date = new Date() @@ -61,6 +61,8 @@ function sendReceipt(recepientEmail, receipt) { }, function(error) { console.error(error) }) + + // ============ GMAIL's ============ // var nodemailerOptions = { // from: process.env.senderMail, // to: receiverEmail, @@ -77,4 +79,4 @@ function sendReceipt(recepientEmail, receipt) { // }) } -sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda") +// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda") diff --git a/package.json b/package.json index 397b018..5ee9f4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "emailnotification", - "version": "1.0.0", + "version": "2.0.0", "description": "", "main": "index.mjs", "type": "module",