add nodemailer and html-to-text

This commit is contained in:
2023-07-11 15:14:24 +02:00
parent 72aae72dcf
commit d763448a12
4 changed files with 221 additions and 4 deletions

View File

@@ -0,0 +1,63 @@
/*
*
* LANGUAGE SCHOOL HOSSEGOR - Booking system
* mailManager.js
*
* Developed 2022 by Janis Hutz
*
*/
// import and init of nodemailer middleware
const mailer = require( 'nodemailer' );
const html2text = require( 'html-to-text' );
// import jsondb.js file and let it import mail config
var transporter = mailer.createTransport( );
class MailManager {
constructor () {
this.options = {
wordwrap: 130
};
}
/*
This method sends a mail with recipient, html, subject and sender as arguments
*/
sendMail ( recipient, html, subject, sender ) {
let text = html2text.convert( html, this.options );
var mailOptions = {
from: sender,
to: recipient,
subject: subject,
html: html,
text: text,
};
transporter.sendMail( mailOptions, function ( error ) {
if ( error ) {
console.log( error );
}
} );
}
sendMailWithAttachment ( recipient, html, subject, attachments, from ) {
let text = html2text.convert( html, this.options );
var mailOptions = {
from: from,
to: recipient,
subject: subject,
html: html,
text: text,
attachments: attachments
};
transporter.sendMail( mailOptions, function ( error ) {
if ( error ) {
console.log( error );
}
} );
}
}
module.exports = MailManager;