Permalink
Browse files

[fix] clients should emit timeout errors to their callbacks

  • Loading branch information...
1 parent 89a1ffb commit 861188b58cdc283f5be4f30fb827ffa90a8a4eaf @bmeck bmeck committed Aug 16, 2011
Showing with 17 additions and 19 deletions.
  1. +17 −19 lib/node_mailer.js
View
@@ -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
@@ -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
@@ -41,35 +41,35 @@ SMTPClientPool.prototype.addClient = function(port,host,options) {
//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 pool.servers[host]
}
}
})
client.on("empty",function(){
- delete hostClients[options.user];
- client.close();})
+ delete hostClients[options.user];
+ client.close();})
}
SMTPClientPool.prototype.send = function send(message, callback) {
- var hostpool = this.servers[message.SERVER.host];
+ var hostpool = this.servers[message.SERVER.host]
if(!hostpool) hostpool = {};
- var user = message.SERVER.user;
- var client = hostpool[user];
+ var client = hostpool[message.SERVER.user]
if(!client) {
- client = hostpool[user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER);
+ client = hostpool[message.SERVER.user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER);
client.on("close",function() {
- if(client == hostpool[user]) {
+ if(client == hostClients[options.user]) {
//only because this could be crazy long lived and dynamic
- delete hostpool[user];
- if(Object.keys(hostpool).length == 0) {
+ delete hostClients[options.user];
+ if(Object.keys(hostClients).length == 0) {
delete pool.servers[host]
}
}
})
client.on("empty",function(){
- delete hostpool[user];
+ delete hostClients[options.user];
client.close();})
}
client.sendMail(message,callback);
+ client.on('error', callback);
}
function merge(x,y) {
@@ -94,7 +94,7 @@ exports.send = function node_mail(message, callback) {
ssl: message.ssl,
user: message.username && message.username.toString(),
pass: message.password && message.password.toString(),
- debug: message.debug
+ debug: true
};
if(message.username || message.password) {
pool.addClient(server.port, server.host, server);
@@ -107,13 +107,13 @@ exports.send = function node_mail(message, callback) {
// If the template is already fully loaded in the cahe
if (_templateCache[message.template].loaded) {
// Use the cached template and send the email
- message.html = mustache.to_html(_templateCache[message.template].template, message.data);
+ message.body = mustache.to_html(_templateCache[message.template].template, message.data);
pool.send(new EmailMessage(merge(message,{
to: message.to,
sender: message.from,
subject: message.subject,
+ body: message.body,
html: message.html,
- attachments: message.attachments,
server: server,
debug: message.debug
})), callback);
@@ -148,7 +148,6 @@ exports.send = function node_mail(message, callback) {
sender: msg.from,
subject: msg.subject,
html: msg.html,
- attachments: message.attachments,
server: server,
debug: msg.debug
})), callback);
@@ -167,7 +166,6 @@ exports.send = function node_mail(message, callback) {
subject: message.subject,
body: message.body,
html: message.html,
- attachments: message.attachments,
server: server,
debug: message.debug
})), callback);

0 comments on commit 861188b

Please sign in to comment.