-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
28 lines (25 loc) · 880 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const express = require("express")
const dotenv = require('dotenv');
dotenv.config({ path: './.env' });
const cron = require("node-cron")
const app = express()
const PORT = process.env.PORT;
const { sendEmail } = require("./emailConfig");
const users = ['pacisprogramming@gmail.com','pacisnkubito@gmail.com']
cron.schedule('0 8 * * 1',function(){
console.log("-- RUNNING THE SCHEDULED CRON JOB --")
users.map(async(user)=>{
let subject = "Automated email"
let text = "This is an automated text sent using node-cron"
let checkSendEmail = await sendEmail(user, subject, text)
if(checkSendEmail == 'success'){
console.log(`Email sent successfully to ${user}`)
}
else{
console.log(`Email was not sent to ${user}`)
}
})
})
app.listen(PORT,()=>{
console.log(`Running on port ${PORT}`)
})