kelektiv / node-cron

Cron for NodeJS.
MIT License
8.42k stars 621 forks source link

How to send email for a particular scheduled date and time ? [Schedule Email Feature] #614

Closed Ak-Ajithkumar closed 1 year ago

Ak-Ajithkumar commented 2 years ago

Description

I tried cron jobs for scheduling but it gets triggered for each and every day at that particular time.

Also workaround Gmail API for scheduling, but there isn't a feature in Gmail API My requirement is to send a scheduled email for the given time by the user.

Here I'm using Postgresql as DB and for backend Nest.js

Kindly help me to figure out this issue.

Screenshots

No response

Additional information

Need to schedule emails like gmail does in nestjs.

IgnisDa commented 2 years ago

It would be better to use something like Redis with a delayed job for this. Cron is somewhat focused on executing multiple times indefinitely.

intcreator commented 1 year ago

another tool might be more appropriate but you should be able to use something like

var CronJob = require('cron').CronJob;
var job = new CronJob(
    '* * * * * *',
    function() {
        console.log('You will see this message every second');
        job.stop() // job will run only once
    },
    null,
    true,
    'America/Los_Angeles'
);
// Use this if the 4th param is default value(false)
// job.start()