-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail.js
44 lines (40 loc) · 1.33 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
var ejs = require('ejs');
var moment = require('moment');
var nodemailer = require('nodemailer');
var config = require('./config');
var db = require('./models');
var transporter = nodemailer.createTransport({
direct: true
});
var defaultFrom = '"Chara Attendance" <[email protected]>';
exports.sendConfirmationEmail = function(checkin) {
if (!config.emailEnabled) return;
db.Checkin.find({
where: {id: checkin.id},
include: [
db.User,
{model: db.Section, include: [db.Course]}
]
}).then(function(checkin) {
db.Student.find({
where: {
courseId: checkin.section.course.id,
uin: checkin.uin
}
}).then(function(student) {
ejs.renderFile('views/email/confirmation.ejs', {
checkin: checkin,
student: student,
checkinTime: moment(checkin.createdAt).format('l LTS')
}, function(err, text) {
if (err) return;
transporter.sendMail({
from: defaultFrom,
to: student.netid + '@illinois.edu',
subject: 'Attendance: ' + checkin.section.course.name + ' - ' + checkin.section.name,
text: text
});
});
});
});
};