nodemailer-smtp-pool
Advanced tools
Comparing version 2.1.0 to 2.2.0
'use strict'; | ||
var SMTPConnection = require('smtp-connection'); | ||
var clone = require('clone'); | ||
var EventEmitter = require('events').EventEmitter; | ||
@@ -37,52 +37,64 @@ var util = require('util'); | ||
PoolResource.prototype.connect = function (callback) { | ||
var returned = false; | ||
if (!this.connection) { | ||
this.connection = new SMTPConnection(this.options); | ||
} | ||
this.connection.once('error', function (err) { | ||
this.emit('error', err); | ||
if (returned) { | ||
return; | ||
this.pool.getSocket(this.options, function (err, socketOptions) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
returned = true; | ||
return callback(err); | ||
}.bind(this)); | ||
this.connection.once('end', function () { | ||
this.close(); | ||
if (returned) { | ||
return; | ||
var returned = false; | ||
var options = this.options; | ||
if (socketOptions && socketOptions.connection) { | ||
this.logger.info('Using proxied socket from %s:%s', socketOptions.connection.remoteAddress, socketOptions.connection.remotePort); | ||
options = clone(options); | ||
Object.keys(socketOptions).forEach(function (key) { | ||
options[key] = socketOptions[key]; | ||
}); | ||
} | ||
returned = true; | ||
return callback(); | ||
}.bind(this)); | ||
this.connection.connect(function () { | ||
if (returned) { | ||
return; | ||
} | ||
this.connection = new SMTPConnection(options); | ||
if (this.options.auth) { | ||
this.connection.login(this.options.auth, function (err) { | ||
if (returned) { | ||
return; | ||
} | ||
returned = true; | ||
this.connection.once('error', function (err) { | ||
this.emit('error', err); | ||
if (returned) { | ||
return; | ||
} | ||
returned = true; | ||
return callback(err); | ||
}.bind(this)); | ||
if (err) { | ||
this.connection.close(); | ||
this.emit('error', err); | ||
return callback(err); | ||
} | ||
this.connection.once('end', function () { | ||
this.close(); | ||
if (returned) { | ||
return; | ||
} | ||
returned = true; | ||
return callback(); | ||
}.bind(this)); | ||
this.connection.connect(function () { | ||
if (returned) { | ||
return; | ||
} | ||
if (this.options.auth) { | ||
this.connection.login(this.options.auth, function (err) { | ||
if (returned) { | ||
return; | ||
} | ||
returned = true; | ||
if (err) { | ||
this.connection.close(); | ||
this.emit('error', err); | ||
return callback(err); | ||
} | ||
this._connected = true; | ||
callback(null, true); | ||
}.bind(this)); | ||
} else { | ||
returned = true; | ||
this._connected = true; | ||
callback(null, true); | ||
}.bind(this)); | ||
} else { | ||
returned = true; | ||
this._connected = true; | ||
return callback(null, true); | ||
} | ||
return callback(null, true); | ||
} | ||
}.bind(this)); | ||
}.bind(this)); | ||
@@ -89,0 +101,0 @@ }; |
@@ -34,2 +34,6 @@ 'use strict'; | ||
if (options && typeof options.getSocket === 'function') { | ||
this.getSocket = options.getSocket; | ||
} | ||
this.options = options && clone(options) || {}; | ||
@@ -88,2 +92,14 @@ | ||
/** | ||
* Placeholder function for creating proxy sockets. This method immediatelly returns | ||
* without a socket | ||
* | ||
* @param {Object} options Connection options | ||
* @param {Function} callback Callback function to run with the socket keys | ||
*/ | ||
SMTPPool.prototype.getSocket = function (options, callback) { | ||
// return immediatelly | ||
return callback(null, false); | ||
}; | ||
/** | ||
* Queues an e-mail to be sent using the selected settings | ||
@@ -90,0 +106,0 @@ * |
{ | ||
"name": "nodemailer-smtp-pool", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "SMTP transport for Nodemailer", | ||
@@ -27,12 +27,12 @@ "main": "lib/smtp-pool.js", | ||
"nodemailer-wellknown": "0.1.7", | ||
"smtp-connection": "2.0.1" | ||
"smtp-connection": "2.2.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"chai": "^3.5.0", | ||
"grunt": "^0.4.5", | ||
"grunt-eslint": "^17.3.1", | ||
"grunt-mocha-test": "^0.12.7", | ||
"mocha": "^2.3.4", | ||
"smtp-server": "^1.7.1" | ||
"mocha": "^2.4.5", | ||
"smtp-server": "^1.8.0" | ||
} | ||
} |
@@ -44,2 +44,3 @@ # SMTP transport module for Nodemailer | ||
* **rateLimit** (defaults to `false`) limits the message count to be sent in a second. Once rateLimit is reached, sending is paused until the end of the second. This limit is shared between connections, so if one connection uses up the limit, then other connections are paused as well | ||
* **getSocket** optional method that is called every time a new connection is made against the SMTP server. This method can provide an existing socket to be used instead of creating a new one | ||
@@ -46,0 +47,0 @@ Alternatively you can use connection url with protocol 'smtp:' or 'smtps:'. Use query arguments for additional configuration values. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26522
549
170
+ Addedsmtp-connection@2.2.1(transitive)
- Removedsmtp-connection@2.0.1(transitive)
Updatedsmtp-connection@2.2.1