-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailReminderService.js
34 lines (31 loc) · 1.1 KB
/
emailReminderService.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
29
30
31
32
33
34
const Checkpoint = require('./models/checkpoint')
const EmailReminder = require('./models/emailreminder')
const emailjs = require('emailjs-com')
// const server = emailjs.server.connect({
// user: "[email protected]",
// password: process.env.EMAIL_PASS,
// host: "smtp.gmail.com",
// ssl: true
// })
const sendEmails = () => {
const now = new Date().getTime()
console.log(now)
let emailList = []
EmailReminder.find({ datetime: { $lte: now}}, function(err, reminders){
if (err) {console.log(err)} else {
reminders.forEach(reminder => {
emailList.push(reminder.email)
})
EmailReminder.deleteMany({ datetime: {$lte: now}}, function(err){
console.log(err)
})
}
})
}
const sendSingleEmail = (emailAddr) => {
//server.send('gmail', 'template_lWIp5bPm', { email: emailAddr})
emailjs.send('gmail', 'template_lWIp5bPm', { email: emailAddr})
.then(res => console.log('email sent'))
.catch(err => console.log(err))
}
//just realized that this will only send emails to the