mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:19:26 +00:00
Added Emailer class to send emails
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const importJSON = require('./importJSON');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeDupes() Removes item from src array that appear in dest
|
* removeDupes() Removes item from src array that appear in dest
|
||||||
*
|
*
|
||||||
@@ -168,6 +170,78 @@ class EmailBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows for email sending
|
||||||
|
*/
|
||||||
|
class Emailer {
|
||||||
|
/**
|
||||||
|
* The host address for the SMTP server to send from
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The username to autheniticate against the SMTP server with
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The password to autheniticate against the SMTP server with
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use an encrypted connection or not
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
#secure = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} [connectionOpts] - The SMTP connection details
|
||||||
|
* @param {string} connectionOpts.host - The host address of the server
|
||||||
|
* @param {string} connectionOpts.user - The SMTP user
|
||||||
|
* @param {string} connectionOpts.password - The SMTP password
|
||||||
|
*/
|
||||||
|
constructor(connectionOpts) {
|
||||||
|
if (typeof connectionOpts === 'undefined')
|
||||||
|
connectionOpts = importJSON('email');
|
||||||
|
|
||||||
|
this.#host = connectionOpts.host;
|
||||||
|
this.#user = connectionOpts.user;
|
||||||
|
this.#password = connectionOpts.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sendEmail() Send an EmailBuilder object as an email
|
||||||
|
*
|
||||||
|
* @param {EmailBuilder} email - The email object to send
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
async sendEmail(email) {
|
||||||
|
console.log(`Sending`);
|
||||||
|
console.log(email);
|
||||||
|
console.log(this.#host,
|
||||||
|
this.#user,
|
||||||
|
this.#password,
|
||||||
|
this.#secure);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the SMTP connection should be encrypted or not
|
||||||
|
* @param {boolean} val - The new value
|
||||||
|
*/
|
||||||
|
set secure(val) {
|
||||||
|
if (typeof val !== 'boolean')
|
||||||
|
throw new Error('Secure must be type boolean');
|
||||||
|
|
||||||
|
this.#secure = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
EmailBuilder: EmailBuilder
|
EmailBuilder: EmailBuilder,
|
||||||
|
Emailer: Emailer
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user