-1

I am looking for a way to send a daily email at specific time using sendgrid. I found the way to schedule it for one time only, but I need it to happen everyday. i.e. seding an email at 12pm everyday.

It's not just for an user. Those who selected an option to receive daily email will get an email.

Here is a scenario. 1. User login 2. Navigate to option page 3. Select an option to get a daily email regarding an user specific update.

Let's say 20 people have selected to receive an email. On my backend I can create an API to fetch each user's data from db to see whether they receive a daily email or not. Probably, I fetch all user's email addresses and email them.

But my question is how do I make my backend run that api at certain time everyday. I use AngularJS for the client side.

notentered
  • 145
  • 2
  • 13

2 Answers2

1

You can use CronJob for this. Something similar to this.

function registerEmailSendingJob() {
    var job = new CronJob({
        cronTime: '0 12 * * *', 
        onTick: function() {
            // send emails
        },
        start: false,
        timeZone: 'Asia/Kathmandu' // put your timezone
    });
    job.start();
}
0

If you prefer to make the API call immediately, SendGrid can handle this for you via the scheduling parameters.

Or if you are using the v3 mail send endpoint, it's even easier; just use the send_at parameter: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html

bwest
  • 9,182
  • 3
  • 28
  • 58