-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.js
62 lines (55 loc) · 1.66 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
58
59
60
61
62
const player = require('play-sound')(opts = {})
const nodemailer = require('nodemailer');
function consoleNotify(location, date) {
console.log(`NOTIFICATION: [${location}] - [${date}]`);
}
async function soundNotify() {
return await new Promise((resolve, reject) => {
player.play('notification.mp3', function(err){
if (err === null) {
resolve();
} else {
reject(err);
}
});
});
}
class EmailNotification {
constructor(sender, password, receivers) {
this.transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
auth: {
user: sender,
pass: password
},
tls: {
ciphers:'SSLv3'
}
});
this.sender = sender;
this.receivers = receivers;
}
async notify(content) {
console.log(`Sending email to ${JSON.stringify(this.receivers)}...`);
const mailOptions = {
from: this.sender,
to: this.receivers,
subject: 'UPDATE from ais.usvisa-info.com !!!',
text: content
};
return new Promise((resolve, reject) => {
this.transporter.sendMail(mailOptions, function(error, info){
if (error) {
reject(error);
} else {
resolve(info);
}
});
});
}
}
module.exports.consoleNotify = consoleNotify;
module.exports.soundNotify = soundNotify;
module.exports.EmailNotification = EmailNotification;