From 469979053cd8fad64facdc5c3c0fd4f6ef4a356e Mon Sep 17 00:00:00 2001 From: admanb Date: Mon, 7 Nov 2011 14:40:17 -0800 Subject: [PATCH 1/4] fixed hostClient issue --- lib/node_mailer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_mailer.js b/lib/node_mailer.js index e1ccb43..2aa145b 100644 --- a/lib/node_mailer.js +++ b/lib/node_mailer.js @@ -56,16 +56,16 @@ SMTPClientPool.prototype.send = function send(message, callback) { if(!client) { client = hostpool[message.SERVER.user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER); client.on("close",function() { - if(client == hostClients[options.user]) { + if(client == hostpool[message.SERVER.user]) { //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 hostpool[message.SERVER.user]; + if(Object.keys(hostpool).length == 0) { + delete pool.servers[host] } } }) client.on("empty",function(){ - delete hostClients[options.user]; + delete hostpool[message.SERVER.user]; client.close();}) } client.sendMail(message,callback); From 9e0557256a9cbf8d08a4ee97398fcc67f7174316 Mon Sep 17 00:00:00 2001 From: admanb Date: Tue, 8 Nov 2011 13:40:54 -0800 Subject: [PATCH 2/4] converted to use jade templating --- lib/node_mailer.js | 13 +++++++++---- package.json | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/node_mailer.js b/lib/node_mailer.js index 2aa145b..dc2fd7d 100644 --- a/lib/node_mailer.js +++ b/lib/node_mailer.js @@ -25,7 +25,8 @@ OTHER DEALINGS IN THE SOFTWARE. var SMTPClient = require("nodemailer").SMTPClient; var EmailMessage = require("nodemailer").EmailMessage; var fs = require('fs'); -var mustache = require('../vendor/mustache'); +var mustache = require('../vendor/mustache') +var jade = require('jade') var _templateCache = {}; function SMTPClientPool() { @@ -41,7 +42,7 @@ 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] } } }) @@ -119,7 +120,9 @@ 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.html = mustache.to_html(_templateCache[message.template].template, message.data); + var jadeFn = jade.compile(_templateCache[message.template].template); + message.html = jadeFn(message.data) dispatchMail(message, server, callback); } else { @@ -146,7 +149,9 @@ exports.send = function node_mail(message, callback) { // "Drain" the queue _templateCache[message.template].queue.push(message); _templateCache[message.template].queue.forEach(function(msg, i){ - msg.html = mustache.to_html(_templateCache[message.template].template, msg.data); + //msg.html = mustache.to_html(_templateCache[message.template].template, msg.data); + var jadeFn = jade.compile(_templateCache[message.template].template); + msg.html = jadeFn(msg.data) dispatchMail(msg, server, callback); }); diff --git a/package.json b/package.json index 342e76b..c6eaac3 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ }, "dependencies": { "nodemailer": "0.1.20", - "colors": ">= 0.3.0" + "colors": ">= 0.3.0", + "jade": ">= 0.0.1" }, "engine": [ "node >=0.3.0" ], "main": "lib/node_mailer" From 7fa933b3e8c93f32ddf3181ca8b1600aed0af2dc Mon Sep 17 00:00:00 2001 From: admanb Date: Tue, 8 Nov 2011 06:40:17 +0800 Subject: [PATCH 3/4] fixed hostClient issue --- lib/node_mailer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_mailer.js b/lib/node_mailer.js index e1ccb43..2aa145b 100644 --- a/lib/node_mailer.js +++ b/lib/node_mailer.js @@ -56,16 +56,16 @@ SMTPClientPool.prototype.send = function send(message, callback) { if(!client) { client = hostpool[message.SERVER.user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER); client.on("close",function() { - if(client == hostClients[options.user]) { + if(client == hostpool[message.SERVER.user]) { //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 hostpool[message.SERVER.user]; + if(Object.keys(hostpool).length == 0) { + delete pool.servers[host] } } }) client.on("empty",function(){ - delete hostClients[options.user]; + delete hostpool[message.SERVER.user]; client.close();}) } client.sendMail(message,callback); From c055f6016982369aa48a2448fdbdc6e20153ed0b Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Sun, 20 May 2012 12:00:53 +0300 Subject: [PATCH 4/4] Fixed ReferenceError: host is not defined --- lib/node_mailer.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node_mailer.js b/lib/node_mailer.js index 2aa145b..0985ffa 100644 --- a/lib/node_mailer.js +++ b/lib/node_mailer.js @@ -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 @@ -53,6 +53,8 @@ SMTPClientPool.prototype.send = function send(message, callback) { var hostpool = this.servers[message.SERVER.host] if(!hostpool) hostpool = {}; var client = hostpool[message.SERVER.user] + var pool = this; + var host = message.SERVER.host; if(!client) { client = hostpool[message.SERVER.user] = new SMTPClient(message.SERVER.host,message.SERVER.port,message.SERVER); client.on("close",function() {