-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotification.js
57 lines (52 loc) · 1.78 KB
/
notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const nodemailer = require('nodemailer');
const smtpTransport = require('nodemailer-smtp-transport');
// Create a Nodemailer transporter
const transporter = nodemailer.createTransport(smtpTransport({
service: 'gmail', // e.g., 'gmail'
host: 'smtp.gmail.com',
auth: {
user: 'task.management.project.bootcamp@gmail.com',
pass: 'jzoj fqqi vhnf pwjd',
},
}));
// Function to send the email
const sendEmail = (to, subject, text) => {
const mailOptions = {
from: 'task.management.project.bootcamp@gmail.com',
to,
subject,
text,
};
console.log(mailOptions)
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.error(error);
}
console.log('Email sent:', info.response);
});
};
// Function to schedule email based on due date
const scheduleEmail = (dueDate, emailDetails) => {
const currentTime = new Date().getTime();
// const dueTime = new Date(dueDate).getTime();
const dueTime = new Date(new Date().getTime()+10000).getTime();
// Calculate time difference in milliseconds
const timeDifference = dueTime - currentTime;
console.log(timeDifference)
if (timeDifference > 0) {
// Schedule the email to be sent when the due date is reached
setTimeout(() => {
sendEmail(emailDetails.to, emailDetails.subject, emailDetails.text);
}, timeDifference);
} else {
console.log('Due date has already passed.');
}
};
// Example usage
const taskDueDate = '2024-01-07T17:30:00Z'; // Replace with your task due date
const emailDetails = {
to: 'ivana.djordjevic@live.ca',
subject: 'Task Due Reminder',
text: 'This is a reminder that your task is due soon.',
};
scheduleEmail(taskDueDate, emailDetails);