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.
nodebb/src/emailer.js

59 lines
1.5 KiB
JavaScript

"use strict";
var fs = require('fs'),
async = require('async'),
path = require('path'),
winston = require('winston'),
templates = require('templates.js'),
User = require('./user'),
Plugins = require('./plugins'),
meta = require('./meta'),
translator = require('../public/src/translator'),
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);
},
email: async.apply(User.getUserField, uid, 'email'),
settings: async.apply(User.getSettings, uid)
}, function(err, results) {
async.map([results.html, results.plaintext, params.subject], function(raw, next) {
translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
next(undefined, translated);
});
}, function(err, translated) {
11 years ago
if(err) {
return winston.error(err.message);
} else if (!results.email) {
11 years ago
return winston.warn('uid : ' + uid + ' has no email, not sending.');
}
Plugins.fireHook('action:email.send', {
to: results.email,
from: meta.config['email:from'] || '[email protected]',
subject: translated[2],
html: translated[0],
plaintext: translated[1],
11 years ago
template: template,
uid: uid
});
});
});
};
module.exports = Emailer;