You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1013 B
JavaScript
45 lines
1013 B
JavaScript
11 years ago
|
var User = require('./user'),
|
||
|
Plugins = require('./plugins'),
|
||
11 years ago
|
Meta = require('./meta'),
|
||
11 years ago
|
|
||
|
fs = require('fs'),
|
||
|
async = require('async'),
|
||
|
path = require('path'),
|
||
|
|
||
11 years ago
|
Emailer = {};
|
||
11 years ago
|
|
||
11 years ago
|
var render = function(template, params, callback) {
|
||
|
if (templates[template] !== null) {
|
||
|
callback(null, templates[template].parse(params));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
callback(null, null);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
Emailer.send = function(template, uid, params) {
|
||
|
async.parallel({
|
||
|
html: function(next) {
|
||
11 years ago
|
render('emails/' + template, params, next);
|
||
11 years ago
|
},
|
||
|
plaintext: function(next) {
|
||
11 years ago
|
render('emails/' + template + '_plaintext', params, next);
|
||
11 years ago
|
}
|
||
|
}, function(err, results) {
|
||
|
User.getUserField(uid, 'email', function(err, email) {
|
||
|
if (!err) {
|
||
|
Plugins.fireHook('action:email.send', {
|
||
11 years ago
|
to: email,
|
||
11 years ago
|
from: Meta.config['email:from'] || '[email protected]',
|
||
|
subject: params.subject,
|
||
11 years ago
|
html: results.html,
|
||
11 years ago
|
plaintext: results.plaintext,
|
||
|
|
||
|
template: template,
|
||
|
uid: uid
|
||
11 years ago
|
});
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports = Emailer;
|