Files
ISPDowntimeMonitor/src/mail.js
KevinMidboe 12a039930b 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.
2020-05-27 20:02:25 +02:00

41 lines
968 B
JavaScript

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