@athenna/mail
Version:
The Athenna email handler. Built on top of nodemailer.
57 lines (56 loc) • 1.37 kB
JavaScript
/**
* @athenna/mail
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Macroable } from '@athenna/common';
import { SMTPServer } from 'smtp-server';
export class SmtpServerImpl extends Macroable {
constructor() {
super(...arguments);
/**
* Set if the SMTP server is listening.
*/
this.isListening = false;
}
/**
* Create the SMTP server instance.
*/
create(options) {
this.server = new SMTPServer(options);
return this;
}
/**
* Start the SMTP server.
*/
async listen(port = 5025, host, backlog) {
return new Promise((resolve, reject) => {
try {
this.server.listen(port, host, backlog);
resolve();
this.isListening = true;
}
catch (err) {
reject(err);
}
});
}
/**
* Close the SMTP Server.
*/
async close() {
return new Promise((resolve, reject) => {
try {
this.server.close();
resolve();
this.isListening = false;
}
catch (err) {
reject(err);
}
});
}
}