mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:19:30 +00:00
Added method to return a nodemailer message object from EmailBuilder
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user