-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.js
37 lines (31 loc) · 1.16 KB
/
mailer.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
const nodemailer = require('nodemailer'),
config = require('./config.json');
let transporter = nodemailer.createTransport({
host: config.mail.host,
port: config.mail.port,
secure: config.mail.port == 465,
auth: {
user: config.mail.auth.user,
pass: config.mail.auth.pass
}
});
const send = async function(subject, text) {
try {
const info = await transporter.sendMail({
from : `"${config.mail.name}" <${config.mail.addr}>`,
to : config.mail.recipients.join(', '),
subject : subject,
text : text
});
console.info(`[ EML ] Message sent: ${info.messageId}`);
} catch(err) {
console.error(`[ EML ] Error: ${err.response}`);
}
}
const alertSilence = () => send('Dead Air ⚠️', 'Silence was detected on the stream.'),
alertSound = () => send('Back On Air 📻', 'Sound was detected on the stream.'),
// TODO: send mail on errors
alertError = () => send('Error 🛑', 'Stream threw an error.');
exports.alertSilence = alertSilence;
exports.alertSound = alertSound;
exports.alertError = alertError;