1
0
mirror of https://github.com/dap-ps/discover.git synced 2025-01-31 11:35:18 +00:00
discover/back-end/emails/base-email.js
2019-06-03 21:01:42 +03:00

35 lines
1.0 KiB
JavaScript

let nodemailer = require('nodemailer');
const SMTP_CONFIG = require('./smtp-config');
const logger = require('./../logger/logger').getLoggerFor('Base-Email');
class BaseEmail {
constructor(from, to, subject, body) {
this.from = from;
this.to = to;
this.subject = subject;
this.text = body;
}
async send() {
let smtpTransporter = nodemailer.createTransport(SMTP_CONFIG);
smtpTransporter.verify().then(
() => {
smtpTransporter.sendMail(this)
.then(() => {
logger.info(`Email with subject ${this.subject} was delivered successfully`);
})
.catch(mailError => {
logger.error(`Email was not delivered due to ${mailError}`);
});
}
).catch(verificationError => {
logger.error(`Email service verification failed due to ${verificationError}`);
});
}
}
module.exports = BaseEmail;