Skip to content

Commit

Permalink
Create emailAutomation.js
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedadnanv authored Jul 13, 2024
1 parent 7583895 commit 4e22e85
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tasks/emailAutomation.js
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);
}
});

0 comments on commit 4e22e85

Please sign in to comment.