nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
863 stars 147 forks source link

Client instantly disconnects with secure enabled #159

Closed dextermb closed 3 years ago

dextermb commented 4 years ago

I have the secure flag enabled and passing in a .key and a .crt file which are renamed .pem files from LetsEncrypt.

Both of these files exist. When trying to connect to the main server via port 465 through Outlook I get the client seems to instantly disconnect.

blackhole_1  | connect
blackhole_1  | [2020-11-27 09:23:53] INFO  [#dckxb4lq7niemdjp] Connection from acme.com
blackhole_1  | [2020-11-27 09:23:53] DEBUG [#dckxb4lq7niemdjp] S: 220 acme.com ESMTP
blackhole_1  | [2020-11-27 09:23:53] INFO  [#dckxb4lq7niemdjp] Connection closed to acme.com
blackhole_1  | disconnect

Note: Sensitive data replaced with "acme.com"

Here's my main mailserver file:

const opts = {
  name: process.env.HOSTNAME,
  authMethods: ['LOGIN'],
  logger: true,
  // --
  onAuth: hook.authenticate,
  onConnect: hook.connect,
  onClose: hook.disconnect,
  onData: hook.data,
  onMailFrom: hook.from,
  onRcptTo: hook.to
}

if (fs.existsSync(constant.CERTS_PATH)) {
  opts.secure = true
  opts.key = fs.readFileSync(path.join(constant.CERTS_PATH, 'private.key'))
  opts.cert = fs.readFileSync(path.join(constant.CERTS_PATH, 'server.crt'))
}

const server = new SMTP(opts)
const port = opts.secure ? 465 : 25

log.info('Starting mailserver')

server.listen(port, () => {
  log.ready(`Mailserver ready on port ${port}`)
})

Any ideas what I might be doing wrong?