Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing error while sending message #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/node_mailer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2009-2010 Marak Squires, Elijah Insua, Fedor Indutny - http://github.com/marak/node_mailer

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
Expand All @@ -8,10 +8,10 @@ copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -53,19 +53,21 @@ SMTPClientPool.prototype.send = function send(message, callback) {
var hostpool = this.servers[message.SERVER.host]
if(!hostpool) hostpool = {};
var client = hostpool[message.SERVER.user]
var pool = this;
var host = message.SERVER.host;
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]) {
if(client == hostpool[message.SERVER.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]
delete hostpool[message.SERVER.user];
if(Object.keys(hostpool).length == 0) {
delete pool.servers[host]
}
}
})
client.on("empty",function(){
delete hostClients[options.user];
delete hostpool[message.SERVER.user];
client.close();})
}
client.sendMail(message,callback);
Expand Down