Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tls support; requires v0.3.x

  • Loading branch information...
commit 7b384b1d81ed8b5a5aadbf0204b308bcc820329e 1 parent 725b997
@deitch deitch authored
Showing with 41 additions and 2 deletions.
  1. +41 −2 lib/node_mailer.js
View
43 lib/node_mailer.js
@@ -154,8 +154,47 @@ Connection.prototype = {
this._connecting = true;
var self = this,
- stream = tcp.createConnection(this.options.port, this.options.host),
- stream_promise = new process.EventEmitter;
+ stream_promise = new process.EventEmitter,
+ connectionHandler;
+
+ connectionHandler = function() {
+ self._stream = stream;
+ self._connecting = false;
+
+ stream.write("helo " + self.options.domain + "\r\n");
+ stream.promise.wait('accepted', function() {
+ if(self.options.authentication === "login") {
+ stream.write("auth login\r\n");
+ stream.write(self.options.username + "\r\n");
+ stream.write(self.options.password + "\r\n");
+
+ if (typeof fn === 'function') {
+ // Set auth callback
+ stream_promise.wait('auth', function(err) {
+ if (err) {
+ try {
+ self.disconnect();
+ } catch (e) {
+ }
+ }
+ fn(err, self._stream);
+ }, self.options.auth_timeout);
+ }
+ } else {
+ if (typeof fn === 'function') {
+ fn(null, self._stream);
+ }
+ }
+ });
+ };
+
+ if (this.options.ssl) {
+ tls = tls || require('tls');
+ stream = tls.connect(this.options.port,this.options.host,connectionHandler);
+
+ } else {
+ stream = tcp.createConnection(this.options.port, this.options.host);
+ }
stream.promise = stream_promise;
Please sign in to comment.
Something went wrong with that request. Please try again.