Skip to content

Commit

Permalink
Merge pull request #114 from antoniodots/master
Browse files Browse the repository at this point in the history
bugfix issue #113: callback called multiple times with error
  • Loading branch information
eleith committed Dec 2, 2014
2 parents 057dfb1 + 232c637 commit 3673748
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions smtp/smtp.js
Expand Up @@ -131,6 +131,9 @@ SMTP.prototype = {

var response = function(err, msg) {
if (err) {
if (self._state === SMTPState.NOTCONNECTED && !self.sock) {
return;
}
self.close(true);
caller(callback, err);
} else if (msg.code == '220') {
Expand Down
30 changes: 30 additions & 0 deletions test/server.js
@@ -0,0 +1,30 @@
var path = require('path');
var assert = require('assert');

describe("Connect to wrong email server", function() {
var emailModulePath = require.resolve(path.join(__dirname, '..', 'email'));
var email;

beforeEach(function() {
if (require.cache[emailModulePath]) {
delete require.cache[emailModulePath];
}
email = require('../email');
});

it("Should not call callback multiple times with wrong server configuration", function(done) {
this.timeout(5000);
var server = email.server.connect({ host: "bar.baz" });
server.send({
from: "foo@bar.baz",
to: "foo@bar.baz",
subject: "hello world",
text: "hello world",
}, function(err) {
assert.notEqual(err, null);
done();
});
});

});

0 comments on commit 3673748

Please sign in to comment.