1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 17:59:25 +00:00

Added method to return a nodemailer message object from EmailBuilder

This commit is contained in:
2022-02-14 20:55:00 +00:00
parent 7bd34f3312
commit 12090cefe8

View File

@@ -5,6 +5,7 @@ const nodemailer = require('nodemailer');
// Import user defined modules
const importJSON = require('./importJSON');
const validator = require('./validator');
/**
* removeDupes() Removes item from src array that appear in dest
@@ -172,6 +173,37 @@ class EmailBuilder {
this.#bcc = removeDupes(this.#bcc, addresses);
return this;
}
/**
* Returns a message object for nodemailer built from message
* @returns {Object}
*/
getMessageObject() {
const message = {
from: this.#from,
to: `${this.#to.join(',')}`,
cc: `${this.#cc.join(',')}`,
bcc: `${this.#bcc.join(',')}`,
subject: this.#subject,
text: this.#body,
};
try {
validator.validate(message, [
'from',
'subject',
'text'
]);
} catch (e) {
console.error(e);
return false;
}
if (typeof this?.#HTMLBody?.length !== 'undefined')
message['html'] = this.#HTMLBody;
return message;
}
}
/**