Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SMTPClientPool.prototype.addClient = function(port,host,options) {
if(this.servers[host] && this.servers[host][options.user]) return;
var hostClients = this.servers[host] || (this.servers[host] = {});
var pool = this;
var client = hostClients[options.user] = new SMTPClient(host,port,options);
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();})
}
SMTPClientPool.prototype.send = function send(message, callback) {
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();})
}
client.sendMail(message,callback);
client.on('error', callback);
}