Ephapox
Ephapox

Reputation: 827

schedule email to send at a later date using nodemailer/node-cron

I have a private beta sign up field that will instantly send an email notifying the user to look out for an approval email with a special key to sign up then send out an email with the special key at a later scheduled date.

send.pre_approval(function(){
  new Cron({
    cronTime: // some later time,
    onTick: function(){
      send.approval()
      this.stop()
    }
  }).start()
})

send.pre_approval will send out the pre_approval email immediately upon signing up for the private beta. The cron job is set to fire some time later and the onTick function that fires at the set cronTime will send out the approval email then call its stop method.

This seems to work as I expected but I was wondering if this is the way to stop the cron job using node-cron.

I'm essentially scheduling a job and stopping it once it runs, it seems like the better way would be to schedule the job to run at a later time from the sign up time, any ideas?

Upvotes: 0

Views: 1857

Answers (1)

Ephapox
Ephapox

Reputation: 827

My co-worker brought up a better solution that makes more sense.

Schedule a cron job that checks the creation_date field of a user that signs up and after a set amount of time has passed since the creation_date send out an email.

This way there is not a cron job for each user.

Upvotes: 1

Related Questions