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.
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
var fs = require('fs'),
|
|
async = require('async'),
|
|
path = require('path'),
|
|
winston = require('winston'),
|
|
|
|
User = require('./user'),
|
|
Plugins = require('./plugins'),
|
|
Meta = require('./meta'),
|
|
Translator = require('../public/src/translator'),
|
|
templates = require('../public/src/templates'),
|
|
|
|
app = {},
|
|
Emailer = {};
|
|
|
|
|
|
Emailer.registerApp = function(expressApp) {
|
|
app = expressApp;
|
|
return Emailer;
|
|
};
|
|
|
|
Emailer.send = function(template, uid, params) {
|
|
async.parallel({
|
|
html: function(next) {
|
|
app.render('emails/' + template, params, next);
|
|
},
|
|
plaintext: function(next) {
|
|
app.render('emails/' + template + '_plaintext', params, next);
|
|
}
|
|
}, function(err, results) {
|
|
User.getUserField(uid, 'email', function(err, email) {
|
|
if(err) {
|
|
return winston.error(err.message);
|
|
}
|
|
|
|
if(!email) {
|
|
return winston.warn('uid : ' + uid + ' has no email, not sending.');
|
|
}
|
|
|
|
Plugins.fireHook('action:email.send', {
|
|
to: email,
|
|
from: Meta.config['email:from'] || '[email protected]',
|
|
subject: params.subject,
|
|
html: results.html,
|
|
plaintext: results.plaintext,
|
|
template: template,
|
|
uid: uid
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = Emailer; |