Skip to content

Node.js based forum software built for the modern web

closes #3756

Julian Lam48b5bab849e5
diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json
index 167ab1aa66..720541d0c1 100644
--- a/public/language/en_GB/error.json
+++ b/public/language/en_GB/error.json
@@ -41,7 +41,6 @@
"no-user": "User does not exist",
"no-teaser": "Teaser does not exist",
"no-privileges": "You do not have enough privileges for this action.",
- "no-emailers-configured": "No email plugins were loaded, so a test email could not be sent",
"category-disabled": "Category disabled",
diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js
index 03acb0091f..565d23e563 100644
--- a/src/controllers/admin/dashboard.js
+++ b/src/controllers/admin/dashboard.js
@@ -22,13 +22,6 @@ dashboardController.get = function(req, res, next) {
doneText: 'Reload not required',
notDoneText:'Reload required'
},
- {
- done: plugins.hasListeners('filter:email.send'),
- doneText: 'Emailer Installed',
- notDoneText:'Emailer not installed',
- tooltip:'Install an emailer plugin from the plugin page in order to activate registration emails and email digests',
- link:'/admin/extend/plugins'
- },
{
done: plugins.hasListeners('filter:search.query'),
doneText: 'Search Plugin Installed',
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 56d15e6e91..f418c16572 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -85,13 +85,10 @@ Controllers.reset = function(req, res, next) {
Controllers.login = function(req, res, next) {
var data = {},
loginStrategies = require('../routes/authentication').getLoginStrategies(),
- emailersPresent = plugins.hasListeners('filter:email.send');
-
- var registrationType = meta.config.registrationType || 'normal';
+ registrationType = meta.config.registrationType || 'normal';
data.alternate_logins = loginStrategies.length > 0;
data.authentication = loginStrategies;
- data.showResetLink = emailersPresent;
data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1 || parseInt(req.query.local, 10) === 1;
data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval';
data.allowLoginWith = '[[login:' + (meta.config.allowLoginWith || 'username-email') + ']]';
diff --git a/src/emailer.js b/src/emailer.js
index 9d5fc2eca5..fc96081b6f 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -1,10 +1,9 @@
"use strict";
-var fs = require('fs'),
- async = require('async'),
- path = require('path'),
+var async = require('async'),
winston = require('winston'),
templates = require('templates.js'),
+ nodemailer = require('nodemailer'),
User = require('./user'),
Plugins = require('./plugins'),
@@ -45,49 +44,18 @@ var fs = require('fs'),
};
Emailer.sendToEmail = function(template, email, language, params, callback) {
- function renderAndTranslate(tpl, params, callback) {
- async.waterfall([
- function(next) {
- render('emails/partials/footer' + (tpl.indexOf('_plaintext') !== -1 ? '_plaintext' : ''), params, next);
- },
- function(footer, next) {
- params.footer = footer;
- render(tpl, params, next);
- },
- function(html, next) {
- translator.translate(html, lang, function(translated) {
- next(null, translated);
- });
- }
- ], callback);
- }
-
- function render(tpl, params, next) {
- if (meta.config['email:custom:' + tpl.replace('emails/', '')]) {
- var text = templates.parse(meta.config['email:custom:' + tpl.replace('emails/', '')], params);
- next(null, text);
- } else {
- app.render(tpl, params, next);
- }
- }
-
callback = callback || function() {};
- if (!Plugins.hasListeners('filter:email.send')) {
- winston.warn('[emailer] No active email plugin found to send "' + template + '" email');
- return callback();
- }
-
var lang = language || meta.config.defaultLang || 'en_GB';
async.waterfall([
function (next) {
async.parallel({
html: function(next) {
- renderAndTranslate('emails/' + template, params, next);
+ renderAndTranslate('emails/' + template, params, lang, next);
},
plaintext: function(next) {
- renderAndTranslate('emails/' + template + '_plaintext', params, next);
+ renderAndTranslate('emails/' + template + '_plaintext', params, lang, next);
},
subject: function(next) {
translator.translate(params.subject, lang, function(translated) {
@@ -112,14 +80,51 @@ var fs = require('fs'),
Plugins.fireHook('filter:email.modify', data, next);
},
function (data, next) {
- Plugins.fireHook('filter:email.send', data, next);
+ if (Plugins.hasListeners('filter:email.send')) {
+ Plugins.fireHook('filter:email.send', data, next);
+ } else {
+ Emailer.sendViaFallback(data, next);
+ }
}
- ], function (err, data) {
+ ], function (err) {
callback(err);
});
};
+ Emailer.sendViaFallback = function(data, callback) {
+ // Some minor alterations to the data to conform to nodemailer standard
+ data.text = data.plaintext;
+ delete data.plaintext;
+ nodemailer.mail(data);
+ callback(null);
+ };
+
+ function render(tpl, params, next) {
+ if (meta.config['email:custom:' + tpl.replace('emails/', '')]) {
+ var text = templates.parse(meta.config['email:custom:' + tpl.replace('emails/', '')], params);
+ next(null, text);
+ } else {
+ app.render(tpl, params, next);
+ }
+ }
+
+ function renderAndTranslate(tpl, params, lang, callback) {
+ async.waterfall([
+ function(next) {
+ render('emails/partials/footer' + (tpl.indexOf('_plaintext') !== -1 ? '_plaintext' : ''), params, next);
+ },
+ function(footer, next) {
+ params.footer = footer;
+ render(tpl, params, next);
+ },
+ function(html, next) {
+ translator.translate(html, lang, function(translated) {
+ next(null, translated);
+ });
+ }
+ ], callback);
+ }
}(module.exports));
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index 29a92dc274..d5ada9d4e0 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -199,14 +199,10 @@ SocketAdmin.settings.clearSitemapCache = function(socket, data, callback) {
};
SocketAdmin.email.test = function(socket, data, callback) {
- if (plugins.hasListeners('filter:email.send')) {
- emailer.send(data.template, socket.uid, {
- subject: '[NodeBB] Test Email',
- site_title: meta.config.title || 'NodeBB'
- }, callback);
- } else {
- callback(new Error('[[error:no-emailers-configured]]'));
- }
+ emailer.send(data.template, socket.uid, {
+ subject: '[NodeBB] Test Email',
+ site_title: meta.config.title || 'NodeBB'
+ }, callback);
};
SocketAdmin.analytics.get = function(socket, data, callback) {
diff --git a/src/user/digest.js b/src/user/digest.js
index f9d4a1092c..cc2c768b71 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -20,10 +20,6 @@ var async = require('async'),
return winston.verbose('[user/jobs] Did not send digests (' + interval + ') because subscription system is disabled.');
}
- if (!plugins.hasListeners('filter:email.send')) {
- return winston.error('[user/jobs] Did not send digests (' + interval + ') because no active email plugin was found.');
- }
-
if (!interval) {
// interval is one of: day, week, month, or year
interval = 'day';