mirror of
https://github.com/KevinMidboe/ISPDowntimeMonitor.git
synced 2025-10-29 17:50:12 +00:00
Check ISP website & send mail if services are down
Scrape, navigate and print ISP's status page for a given address. This only works with telenor and the URL must be a search for a given address. If any services are found to be down a mail is sent from and to accounts set in config.js.
This commit is contained in:
40
src/mail.js
Normal file
40
src/mail.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const nodemailer = require( 'nodemailer')
|
||||
const config = require('../config.js')
|
||||
|
||||
class Mail {
|
||||
constructor(sender=undefined, password=undefined, recipient=undefined) {
|
||||
this.sender = sender || config.senderEmail;
|
||||
this.password = password || config.senderPassword;
|
||||
this.recipient = recipient || config.recipientEmail;
|
||||
this.transporter = this.setupTransporter();
|
||||
}
|
||||
|
||||
setupTransporter() {
|
||||
return nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: this.sender,
|
||||
pass: this.password
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
sendMail = message => this.transporter.sendMail(message);
|
||||
|
||||
sendAttachment = fileRef => {
|
||||
const message = {
|
||||
from: `"Fred Foo 👻" <${this.sender}>`,
|
||||
to: this.recipient,
|
||||
subject: 'Telenor nedetid',
|
||||
text: "hello wordl",
|
||||
html: "<p>hello wordl</p>",
|
||||
attachments: [{
|
||||
path: fileRef
|
||||
}]
|
||||
}
|
||||
|
||||
return this.sendMail(message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Mail
|
||||
Reference in New Issue
Block a user