crash: hostClients is not defined #51

Open
defunctzombie opened this Issue Oct 24, 2011 · 8 comments

Comments

Projects
None yet
9 participants

In /lib/node_mailer.js:68

the hostClients variable is not in scope here.

More info:
ReferenceError: hostClients is not defined
at SMTPClient. (/var/www/truco/node_modules/mailer/lib/node_mailer.js:68:6)
at SMTPClient.emit (events.js:61:17)
at SMTPClient._flushMessages (/var/www/truco/node_modules/mailer/node_modules/nodemailer/lib/smtp.js:146:14)
at Object.callback (/var/www/truco/node_modules/mailer/node_modules/nodemailer/lib/smtp.js:235:22)
at SMTPClient._dataListener (/var/www/truco/node_modules/mailer/node_modules/nodemailer/lib/smtp.js:468:20)
at SMTPClient. (/var/www/truco/node_modules/mailer/node_modules/nodemailer/lib/smtp.js:642:14)
at CleartextStream. (native)
at CleartextStream.emit (events.js:64:17)
at CleartextStream._push (tls.js:299:12)
at SecurePair.cycle (tls.js:577:20)

Looks like it was a copy and paste from addClient

The below is a quick fix (at least its working for me)

NOTES
hostClient => hostpool
options => message.SERVER

SMTPClientPool.prototype.send = function send(message, callback) {
  var hostpool = this.servers[message.SERVER.host]
  if(!hostpool) hostpool = {};
  var client = hostpool[message.SERVER.user]
  if(!client) {
    client = hostpool[message.SERVER.user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER);
    client.on("close",function() {
      if(client == hostpool[message.SERVER.user]) {
          //only because this could be crazy long lived and dynamic
          delete hostpool[message.SERVER.user];
          if(Object.keys(hostpool).length == 0) {
            delete pool.servers[host]
          }
        }
    })
    client.on("empty",function(){
     delete hostpool[message.SERVER.user];
     client.close();})
  }
  client.sendMail(message,callback);
  client.on('error', callback);
}

dobesv commented Nov 14, 2011

That fix worked for me, thanks!

For some reason this error only showed up on production and not in my dev/staging environments. Strange, I guess the "empty" event doesn't always get called. Maybe it depends on the mailserver?

Same bug here, the fix worked but I'm wondering why you didn't change it in the official npm release...

marook commented Jan 30, 2012

same issue here... would be cool to have a new npm release :-)

btw... travisperson's solution works for me.

same here, quick fix works for me too.

please update npm package

is the npm package fixed for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment