-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
34 lines (30 loc) · 1013 Bytes
/
mail.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 sgMail = require('@sendgrid/mail')
const cron = require('node-cron')
const { request } = require('@sendgrid/client')
var sendFunc = (users)=>
{
sgMail.setApiKey(process.env.SENDGRID_API)
const msg = {
to: users,
from: '[email protected]',
subject: 'Vaccination stats for today',
text: 'These are the COVID stats for today:',
html: '<strong>These are the COVID vaccination stats for today:</strong><br><a href = "https://india-covid19vaccine.github.io/csv/national_timeline.csv">National Timeline</a><br><br><a href = "https://india-covid19vaccine.github.io/csv/state_timeline.csv">Statewise Timeline</a>',
}
sgMail
.send(msg,true)
.then(() => {
console.log('Email sent')
})
.catch((error) => {
console.error(error)
})
}
const start =(users)=>{
// console.log(users);
cron.schedule('0 21 * * *', () => {
console.log('Sending daily emails at 9pm');
sendFunc(users);
});
}
module.exports = start