(Open to suggestion on the lingo up there)
I'm trying to set up a simple email sender from a node console app. After reading this answer node-email-templates
seems like the way to go. But I can't figure out how to get this library to work in an "initialize now, use later" style object. The example code doesn't do that, it's initializing the object and sending at the same time. Node-mailer gives a good example of the style I'm used to:
var nodemailer = require("nodemailer");
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore,
// uncomment following line:
// smtpTransport.close(); // shut down the connection pool, no more messages
});
What I'd really like to be able to do:
// require node-email-templates
// setup smtp transport, store it as a property of another object,
// let's call it Alert
// when an alert needs to send an email it will pick a template
// name and tell node-email-templates to send that template,
// with appropriate local variables
This doesn't seem unusual in any way but damned if I can get it to work based on the sample code that is provided.