Permalink
Browse files

modified send() to accept a callback so you can handle errors, if any

  • Loading branch information...
1 parent ca61167 commit 186590f7e27565a45c610b7f3e6c46b2d01b0a9d @deepthawtz deepthawtz committed with Nov 3, 2010
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/node_mailer.js
View
@@ -38,8 +38,9 @@ var tcp = require('net'),
exports.connections = connections;
-var Connection = function(options) {
+var Connection = function(options, callback) {
this.options = options;
+ this.callback = callback;
};
Connection.prototype = {
options : {},
@@ -119,12 +120,14 @@ Connection.prototype = {
});
stream.on("error", function() {
+ self.callback(new Error("could not connect"));
stream.destroy();
self._connecting = false;
stream = null;
});
stream.on("end", function() {
+ self.callback(null);
self._connecting = false;
self._stream = null;
});
@@ -153,15 +156,15 @@ Connection.prototype = {
}
};
-var Email = function(options) {
+var Email = function(options, callback) {
this.options = options;
this.options.body = this.lineWrap(this.options.body);
// create a new connection if needed
var connectionKey = [options.host, options.port].join(':');
if (!connections[connectionKey]) {
- connections[connectionKey] = new Connection(options);
+ connections[connectionKey] = new Connection(options, callback);
}
// queue this email in the appropriate connection
@@ -188,7 +191,7 @@ Email.prototype = {
}
};
-exports.send = function(options) {
+exports.send = function(options, callback) {
var i, key;
options = options || {};
@@ -200,5 +203,5 @@ exports.send = function(options) {
}
}
- return new Email(options);
+ return new Email(options, callback);
};

0 comments on commit 186590f

Please sign in to comment.