From af37210c0bd7bf343fe366ddd2b253e2214f5547 Mon Sep 17 00:00:00 2001 From: Josh Morel Date: Sat, 15 Dec 2018 08:51:51 -0500 Subject: throw error if MailDev doesn't run also allow calling in multiple file --- shared/utils/miscs/email-child-process.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 shared/utils/miscs/email-child-process.js (limited to 'shared/utils/miscs/email-child-process.js') diff --git a/shared/utils/miscs/email-child-process.js b/shared/utils/miscs/email-child-process.js new file mode 100644 index 000000000..40ae37d70 --- /dev/null +++ b/shared/utils/miscs/email-child-process.js @@ -0,0 +1,27 @@ +const MailDev = require('maildev') + +// must run maildev as forked ChildProcess +// failed instantiation stops main process with exit code 0 +process.on('message', (msg) => { + if (msg.start) { + const maildev = new MailDev({ + ip: '127.0.0.1', + smtp: 1025, + disableWeb: true, + silent: true + }) + + maildev.on('new', email => { + process.send({ email }) + }) + + maildev.listen(err => { + if (err) { + // cannot send as Error object + return process.send({ err: err.message }) + } + + return process.send({ err: null }) + }) + } +}) -- cgit v1.2.3