UNPKG

@timshel_npm/maildev

Version:

SMTP Server with async API and Web Interface for viewing and testing emails during development

50 lines (49 loc) 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MailDev = void 0; const mailserver_1 = require("./lib/mailserver"); const web_1 = require("./lib/web"); const logger = require("./lib/logger"); class MailDev extends mailserver_1.MailServer { constructor(config, mailEventSubjectMapper) { var _a, _b, _c; if (config === null || config === void 0 ? void 0 : config.verbose) { logger.setLevel(2); } else if (config === null || config === void 0 ? void 0 : config.silent) { logger.setLevel(0); } // Start the Mailserver super(config, mailEventSubjectMapper); // Start the web server if (!((_a = config === null || config === void 0 ? void 0 : config.web) === null || _a === void 0 ? void 0 : _a.disabled)) { // Default to run on same IP as smtp const host = ((_b = config === null || config === void 0 ? void 0 : config.web) === null || _b === void 0 ? void 0 : _b.host) ? (_c = config === null || config === void 0 ? void 0 : config.web) === null || _c === void 0 ? void 0 : _c.host : config === null || config === void 0 ? void 0 : config.host; this.web = new web_1.Web(this, Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.web), { host })); } if (config === null || config === void 0 ? void 0 : config.logMailContents) { this.on("new", function (mail) { const mailContents = JSON.stringify(mail, null, 2); logger.info(`Received the following mail contents:\n${mailContents}`); }); } process.on("SIGTERM", this.close.bind(this)); process.on("SIGINT", this.close.bind(this)); } listen() { const p = [super.listen()]; if (this.web) { p.push(this.web.listen()); } return Promise.all(p); } close() { logger.info("Received shutdown signal, shutting down now..."); const p = [super.close()]; if (this.web) { p.push(this.web.close()); } return Promise.all(p); } } exports.MailDev = MailDev;