Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Simplify SMTPClientPool.prototype.send #62

Open
wants to merge 1 commit into from

1 participant

Jason LuBean
Jason LuBean

Simplify SMTPClientPool.prototype.send by reusing the code from SMTPClientPool.prototype.addClient. This also fixes "ReferenceError: hostClients is not defined" issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2012
  1. Jason LuBean

    Simplify SMTPClientPool.prototype.send by reusing the code from SMTPC…

    jlubean authored
    …lientPool.prototype.addClient
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 19 deletions.
  1. +4 −19 lib/node_mailer.js
23 lib/node_mailer.js
View
@@ -47,27 +47,12 @@ SMTPClientPool.prototype.addClient = function(port,host,options) {
})
client.on("empty",function(){
delete hostClients[options.user];
- client.close();})
+ client.close();});
+ return client;
}
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 == hostClients[options.user]) {
- //only because this could be crazy long lived and dynamic
- delete hostClients[options.user];
- if(Object.keys(hostClients).length == 0) {
- delete pool.servers[host]
- }
- }
- })
- client.on("empty",function(){
- delete hostClients[options.user];
- client.close();})
- }
+ var hostClients = this.servers[message.SERVER.host] || (this.servers[message.SERVER.host] = {});
+ var client = hostClients[message.SERVER.user] || this.addClient(message.SERVER.port,message.SERVER.host,message.SERVER);
client.sendMail(message,callback);
client.on('error', callback);
}
Something went wrong with that request. Please try again.