Skip to content
Advertisement

Booking reminder Nodemailer node-cron MongoDB

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:

JavaScript

enter image description here

JavaScript

I think start time parse to date? How read only this reservation which will be in a week?

Advertisement

Answer

model: ***(i changed start_time to type: Date and i added email_sent)

JavaScript

Server:

JavaScript

*Also i will suggest to do, find only email_sent : false. you can check how to do it with mongoose. (then you dont need to check it in the if statement) *Model.find({ email_sent: “false” })

i just did it out of my mind, i didnt check, errors you can face:

  1. you will need to convert the start_time
  2. check the boolean email_sent how you get it (as a string or boolen) it will affect the if statement.

this is just the idea how to achieve it. i didnt test the code. Please try the code and let me know if you face any issues

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement