Quellcode durchsuchen

sendinblue email sending

master
mikeyangelo5 vor 2 Jahren
Ursprung
Commit
368956a212
4 geänderte Dateien mit 2305 neuen und 2 gelöschten Zeilen
  1. +80
    -0
      index.js
  2. +0
    -0
      index.mjs
  3. +2221
    -0
      package-lock.json
  4. +4
    -2
      package.json

+ 80
- 0
index.js Datei anzeigen

@@ -0,0 +1,80 @@
import express from 'express'
import cors from 'cors'
import bodyParser from 'body-parser'
import amqp from 'amqplib'
// import nodemailer from 'nodemailer'
import SibApiV3Sdk from 'sib-api-v3-sdk'
import dotenv from 'dotenv'
dotenv.config()

const app = express()
const queue = process.env.queueName
const senderEmail = "michael.pandu@ti.ukdw.ac.id"
// const mailTransporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: process.env.transporter_username,
// pass: process.env.transporter_passcode
// }
// })
var defaultClient = SibApiV3Sdk.ApiClient.instance
var apiKey = defaultClient.authentications['api-key']
apiKey.apiKey = process.env.sendinblue_api_key
var apiInstance = new SibApiV3Sdk.TransactionalEmailsApi()
var sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail()

app.use(cors())
app.use(bodyParser.json())

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)

function sendReceipt(recepientEmail, receipt) {
var date = new Date()
sendSmtpEmail = {
sender: {email: senderEmail, name: 'ReceiptSenderAutomation'},
to: [{email: recepientEmail, name: 'Customer'}],
subject: "test",
textContent: "testing",
htmlContent: "<h1>test</h1>"
}
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + data)
console.log(date.toLocaleString())
}, function(error) {
console.error(error)
})
// var nodemailerOptions = {
// from: process.env.senderMail,
// to: receiverEmail,
// subject: "Nota " + date.toLocaleDateString(),
// text: receiptToSend
// }
// mailTransporter.sendMail(nodemailerOptions, function(err, info) {
// if (err) {
// console.log(err.message)
// }
// if (info) {
// console.log(`Email sent!` + " | " +today.toLocaleTimeString("id"))
// }
// })
}

sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda")

+ 0
- 0
index.mjs Datei anzeigen


+ 2221
- 0
package-lock.json
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 4
- 2
package.json Datei anzeigen

@@ -3,8 +3,9 @@
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "nodemon index.mjs"
},
"repository": {
"type": "git",
@@ -19,6 +20,7 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"nodemailer": "^6.9.0",
"nodemon": "^2.0.20"
"nodemon": "^2.0.20",
"sib-api-v3-sdk": "^8.5.0"
}
}

Laden…
Abbrechen
Speichern