aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/extra-utils/miscs/email-child-process.js
blob: 088a5a08c034440b2b88c724b7ce9b2b8e44576d (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                           
                     

















                                                 
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: msg.port,
      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 })
    })
  }
})