-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7583895
commit 4e22e85
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const cron = require('node-cron'); | ||
const sendEmail = require('../modules/emailSender'); | ||
const getCornAIUsers = require('../services/userService'); | ||
|
||
// Define a cron job to run at a specific interval (e.g., every day at 9 AM) | ||
cron.schedule('0 9 * * *', async () => { | ||
try { | ||
const users = await getCornAIUsers(); | ||
|
||
for (const user of users) { | ||
const subject = 'Your Daily Update from ${company.on}'; | ||
const text = `Hello ${user.name},\n\nHere is your daily update...`; | ||
const html = `<p>Hello ${user.name},</p><p>Here is your daily update...</p>`; | ||
|
||
await sendEmail(user.email, subject, text, html); | ||
} | ||
} catch (error) { | ||
console.error('Error in email automation:', error); | ||
} | ||
}); |