mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:19:26 +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
|
// Import user defined modules
|
||||||
const importJSON = require('./importJSON');
|
const importJSON = require('./importJSON');
|
||||||
|
const validator = require('./validator');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeDupes() Removes item from src array that appear in dest
|
* removeDupes() Removes item from src array that appear in dest
|
||||||
@@ -172,6 +173,37 @@ class EmailBuilder {
|
|||||||
this.#bcc = removeDupes(this.#bcc, addresses);
|
this.#bcc = removeDupes(this.#bcc, addresses);
|
||||||
return this;
|
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