I'm using Nodemailer to sent email from my app. When preparing a email an options object is made. This object is later passed to the sendmail function.
The options looks like this:
var mailOptions = {
from: 'Fred Foo <foo@blurdybloop.com>',
to: 'bar@blurdybloop.com, baz@blurdybloop.com',
subject: 'Hello Mr ' + doc.name,
text: 'Some long body text with ' + doc.variables + ' come here... ',
};
I would like to move the subect and body text to a module for easier writing without cluttering my main app file. But as seen above the subject and bodytext are using variables doc.name and doc.variables that exist in the context surrounding the current mailOptions object.
I want something like this:
var email = require (./email);
var mailOptions = {
from: 'Fred Foo <foo@blurdybloop.com>',
to: 'bar@blurdybloop.com, baz@blurdybloop.com',
subject: email.signup.subject,
text: email.signup.body,
};
But I can't seems to get it to work. Either an error is thrown at startup because there is unknown variables in the module, or the variables doc.name and doc.variables are "undefined" in the outgoing email.