|
|
|
|
@ -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 : `)
|
|
|
|
|
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)
|
|
|
|
|
}, { 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")
|