Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions demo-template-partials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var email = require("./lib/node_mailer");

email.send({
host : "localhost", // smtp server hostname
port : "25", // smtp server port
domain : "localhost", // domain used by client to identify itself to server
to : "[email protected]",
from : "[email protected]",
subject : "node_mailer test email",
template : "./templates/sample-partials.txt", // path to template name
data : {
"username": "Billy Bob",
"color": function(){
var arr = ["purple", "red", "green", "yellow"];
return arr[Math.floor(Math.random()*3)];
},
"animal": "monkey",
"adverb": "quickly",
"noun": "hot lava",
"cats": {
"plural_noun": "cats",
"verb": "rule",
"proper_noun": "Internet"
}
},
partials: {"cats": "{{plural_noun}} {{verb}} the {{proper_noun}}"},
authentication : "login", // auth login is supported; anything else is no auth
username : undefined, // username
password : undefined, // password
debug: true // log level per message
},
function(err, result){
if(err){ console.log(err); }
});
4 changes: 2 additions & 2 deletions lib/node_mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ 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, message.partials);
dispatchMail(message, server, callback);
}
else {
Expand All @@ -146,7 +146,7 @@ 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, message.partials);
dispatchMail(msg, server, callback);
});

Expand Down
9 changes: 9 additions & 0 deletions templates/sample-partials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Hello {{username}},

This is a sample template of the node mailer.

It uses mustache templating to do basic search and replaces.

The {{color}} {{animal}} {{adverb}} ran over the {{noun}}.

Also, {{>cats}}.