0👍
cron.schedule('*/10 * * * * *', () => {
// other code goes here
})
//This will run after every 10 sec
0👍
To send email from a node-cron script, you’ll need the nodemailer npm package. Following that, you must configure your email by importing the package into your node-cron file and specifying the sending details for your message, a transporter, and mailoption:
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'yoursendingmail',
pass:'yoursendingpassword'
},
const mailOptions = {
from: 'xyz@gmail.com',
to: 'abc@gmail.com,
subject: 'sub here',
html: '<p>text here</p>'}
};)
after, you set up the node-cron like this:
cronJob.schedule('10 * * * * *', () => {
transporter.sendMail(mailOptions, function (err, info)
{
if(err){}
else{}//can log info here if email is sent
}
})
Source:stackexchange.com