diff --git a/lib/node_mailer.js b/lib/node_mailer.js index e1ccb43..191db34 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 @@ -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] } } }) @@ -53,19 +54,21 @@ 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() { - 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); @@ -119,7 +122,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 +151,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"