nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 145 forks source link

SMTP server crashes occasionally #117

Open joodies opened 5 years ago

joodies commented 5 years ago
const smtpServerConfig = Object.assign({
    onAuth: smtpHelpers.createOnAuthCallback(user, password),
    onData: handleDataStream,
    onRcptTo: handleRecipientAddress,
    onClose: handleClientClosed,
    logger: false,
    disabledCommands: (user && password) ? ['STARTTLS'] : ['AUTH']
  }, hideExtensionOptions)

  const smtp = new SMTPServer(smtpServerConfig)

  smtp.on('error', mailServer.onSmtpError)

Exception stack: Error: read ETIMEDOUT at exports._errnoException (util.js:1020:11) at TCP.onread (net.js:568:26);

The nodemailer server crashes sporadically from SMTP error event, I'm gonna try heapdump to see what's going on.

gbhrdt commented 5 years ago

I'm using SMTP Server for bounce messages and receiving a similar exception.

const server = new SMTPServer({
  authOptional: true,
  onRcptTo: Meteor.bindEnvironment((address, session, callback) => {
    var bounce = address.address.match(/^bounce-([^@]+)-([^@]+)-([^@]+)@/);
    if (bounce && bounce[1] && bounce[2] && bounce[3]) {
      session.bounceType = bounce[1];
      session.bounceId = bounce[2];
      session.bounceContactId = bounce[3];
      session.isBounce = true;
      console.log('Bounced message with type %s, id %s and contactId %s', session.bounceType, session.bounceId, session.bounceContactId);
      return callback(); // Accept the address
    }
    const err = new Error('Invalid bounce mail received');
    err.responseCode = 400;
    return callback(err);
  }),
  onData: Meteor.bindEnvironment((stream, session, callback) => {
    if (session.isBounce) {
      const chunks = [];
      stream.on('data', (data) => {
        chunks.push(data);
      });
      stream.on('end', Meteor.bindEnvironment(() => {
        const content = Buffer.concat(chunks).toString('utf8');
        // ...  (process content)
        callback();
      }));
    } else {
      // ignore message data
      stream.on('data', () => {});
      stream.on('end', callback);
    }
  })
});

server.listen(2525);

Error:

events.js:183
      throw er; // Unhandled 'error' event
      ^
Error: read ECONNRESET
    at _errnoException (util.js:1024:11)
    at TCP.onread (net.js:615:25)
markcellus commented 1 year ago

Hey @joodies did you ever figure out a resolution to issue? Thanks