forked from Databaseprogramming-Sunshine/Sunshine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.js
87 lines (77 loc) ยท 2.88 KB
/
email.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
const nodemailer = require("nodemailer");
const schedule = require("node-schedule");
const connection = require("./config/db");
exports.surveyEmail = function () {
connection.query(
"select course_id, course_name, date_format(survey_date, '%Y%m%d') as survey_date from course order by survey_date",
function (err, rows) {
let context3 = [];
for (var i = 0; i < rows.length; i++) {
const date = new Date(
rows[i].survey_date.substring(0, 4),
rows[i].survey_date.substring(4, 6) - 1,
rows[i].survey_date.substring(6, 8),
21,
28,
50,
);
context3.push(date);
let surveyDate = rows[i].survey_date;
let courseName = rows[i].course_name;
let courseId = rows[i].course_id;
var job = schedule.scheduleJob(context3[i], function () {
let context = [];
console.log("์๋
");
connection.query(
"select distinct attendance.student_id from course join attendance where course.course_id = attendance.course_id and course.survey_date = ? and attendance.course_id = ?",
[surveyDate, courseId],
function (err, rows1) {
for (var j = 0; j < rows1.length; j++) {
connection.query(
"select distinct student.email from student join attendance where student.student_id = attendance.student_id and student.student_id = ? ",
[rows1[j].student_id],
function (err, rows2) {
if (err) {
throw err;
}
context.push(rows2[0].email + ","); //๋ณด๋ด๋ ์ด๋ฉ์ผ context์ ์ ์ฅ}
}
);
}
}
);
// e-mail message options
const mailOptions = {
from: "[email protected]",
to: context, //๋ณด๋ด๋ ์ด๋ฉ์ผ
subject: "sunshine ํน๊ฐ ๋ง์กฑ๋ ์กฐ์ฌ", //๋ฉ์ผ ์ ๋ชฉ
html:
courseName +
" ๋ง์กฑ๋ ์กฐ์ฌ ์ฐธ์ฌ ๋ถํ๋๋ฆฝ๋๋ค" +
" <p>https://sunshine.sungshin.ac.kr</p>",
//๋ฉ์ผ ๋ด์ฉ
};
// e-mail transport configuration
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]", //์์ด๋
pass: "sunshine!12", //๋น๋ฒ
},
tls: {
rejectUnauthorized: false,
},
});
// Send e-mail
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
});
}
}
);
};