mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
closes #3271
This commit is contained in:
@@ -20,48 +20,62 @@ var fs = require('fs'),
|
||||
};
|
||||
|
||||
Emailer.send = function(template, uid, params, callback) {
|
||||
if (!callback) { callback = function() {}; }
|
||||
callback = callback || function() {};
|
||||
if (!app) {
|
||||
winston.warn('[emailer] App not ready!');
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
email: async.apply(User.getUserField, uid, 'email'),
|
||||
settings: async.apply(User.getSettings, uid)
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
if (!results.email) {
|
||||
winston.warn('uid : ' + uid + ' has no email, not sending.');
|
||||
return next();
|
||||
}
|
||||
params.uid = uid;
|
||||
Emailer.sendToEmail(template, results.email, results.settings.userLang, params, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Emailer.sendToEmail = function(template, email, language, params, callback) {
|
||||
callback = callback || function() {};
|
||||
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) {
|
||||
if (err) {
|
||||
winston.error('[emailer] Error sending digest : ' + err.stack);
|
||||
return callback(err);
|
||||
}
|
||||
async.map([results.html, results.plaintext, params.subject], function(raw, next) {
|
||||
translator.translate(raw, results.settings.userLang || meta.config.defaultLang || 'en_GB', function(translated) {
|
||||
translator.translate(raw, language || meta.config.defaultLang || 'en_GB', function(translated) {
|
||||
next(undefined, translated);
|
||||
});
|
||||
}, function(err, translated) {
|
||||
if (err) {
|
||||
winston.error(err.message);
|
||||
return callback(err);
|
||||
} else if (!results.email) {
|
||||
winston.warn('uid : ' + uid + ' has no email, not sending.');
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (Plugins.hasListeners('action:email.send')) {
|
||||
Plugins.fireHook('action:email.send', {
|
||||
to: results.email,
|
||||
to: email,
|
||||
from: meta.config['email:from'] || 'no-reply@localhost.lan',
|
||||
subject: translated[2],
|
||||
html: translated[0],
|
||||
plaintext: translated[1],
|
||||
template: template,
|
||||
uid: uid,
|
||||
uid: params.uid,
|
||||
pid: params.pid,
|
||||
fromUid: params.fromUid
|
||||
});
|
||||
@@ -72,6 +86,10 @@ var fs = require('fs'),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}(module.exports));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user