I'm trying to set-up a cron email job based on a timestamp in a column in a MongoDB database, here is the code I have tried so far...
let CronJob = require('cron').CronJob;
let nodemailer = require('nodemailer');
//user.timestamp is a field in a MongoDB database
new CronJob('* * * * * *', function() {
if(Date.now().toString() === user.timestamp){
let message = {
// Relevant message stuff here
};
transporter.sendMail(message, (error, info) => {
if (error) {
console.log('Error occurred');
console.log(error.message);
return process.exit(1);
}
console.log('Message sent successfully!');
// only needed when using pooled connections
transporter.close();
});
}
});
... However, the email isn't firing out a message. Any ideas on how I can set the cron job to run whenever a UNIX timestamp matches up to the current date/time?