I am having problem sending a booking reminder email. I use nodemailer and node-cron. It works good. I would like to read date from database and e.g. send email one week before reservation. I have no idea how to do it. My model:
start_time: {
type: String,
required: true,
},
hour: {
type: String,
required: true,
},
courtId: {
type: String,
required: true,
},
userId: {
type: ObjectId,
ref: 'userModel',
required: true,
},
});
const cron = require('node-cron');
const nodemailer = require('nodemailer');
const { getMaxListeners } = require('../config/database');
const sendEmail = function () {
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: `${process.env.EMAIL_ADDRESS}`,
pass: `${process.env.EMAIL_PASSWORD}`,
},
});
const mailOptions = {
from: `${process.env.EMAIL_ADDRESS}`,
to: `${''}`,
subject: 'Link To Reset Password',
text:
'wiadomosć',
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
};
module.exports.task = function () {
cron.schedule('00 * * * * *', () => {
console.log('send');
//sendEmail();
});
};
I think start time parse to date? How read only this reservation which will be in a week?