-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReminderScheduler.js
94 lines (92 loc) · 2.5 KB
/
ReminderScheduler.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const nodemailer = require('nodemailer');
const connectDB = require('./config/db');
connectDB();
const Reminder = require('./models/Reminder');
const dateFormat = () => {
var d1 = new Date();
var d =
d1.getFullYear() +
'-' +
(d1.getMonth() + 1 < 10 ? '0' : '') +
(d1.getMonth() + 1) +
'-' +
(d1.getDate() < 10 ? '0' : '') +
d1.getDate() +
' ' +
(d1.getHours() < 10 ? '0' : '') +
d1.getHours() +
':' +
(d1.getMinutes() < 10 ? '0' : '') +
d1.getMinutes();
return d;
};
getReminders = async () => {
try {
// var d1 = new Date();
// var d2 = new Date(d1.getFullYear(),d1.getMonth(),d1.getDate(),d1.getHours(),d1.getMinutes());
// var d = d1.getFullYear()+'-'+d1.getMonth()+'-'+d1.getDate()+'-'+d1.getHours()-1+'-'+d1.getMinutes();
// console.log(d);
let reminders = await Reminder.find({ date: dateFormat() });
// console.log(reminders);
reminders.forEach(async reminder => {
sendmail(reminder.email, reminder.text);
});
} catch (err) {
console.error('Error');
}
};
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '20020809me'
}
});
sendmail = (id, text) => {
transporter.sendMail(
{
from: '[email protected]',
to: id,
subject: 'A Reminder For You',
text: text
},
function(err, info) {
if (err) console.error(err);
else console.log('Sent Successfully to ' + id);
}
);
};
getReminders();
// var nodemailer = require('nodemailer');
// const Reminder = require('./Reminder');
// const connectDB = require('./db');
// connectDB();
// var transporter = nodemailer.createTransport({
// service: 'gmail',
// auth:{
// user: '[email protected]',
// pass: '20020809me'
// }
// });
// getReminders = async () => {
// try {
// var currReminders = await Reminder.find({date: "2019-10-11T18:30:00.000+00:00"})
// console.log(currReminders);
// currReminders.forEach(element => {
// const mailOptions = {
// from: '[email protected]',
// to: element.email,
// //subject: 'nodemailer check krwa ra tha muskan se - nitish',
// text: element.test
// };
// transporter.sendMail(mailOptions,function(err,info){
// if(err)
// console.log(err);
// console.log('sent succesfully');
// });
// });
// } catch(err){
// console.error(err);
// }
// }
// getReminders();