Move send_test_mail under mail domain api

This commit is contained in:
Girish Ramakrishnan
2018-01-23 16:10:23 -08:00
parent ccaf687e91
commit d33e35fda2
5 changed files with 38 additions and 17 deletions
+1 -13
View File
@@ -15,8 +15,7 @@ exports = module.exports = {
feedback: feedback,
checkForUpdates: checkForUpdates,
getLogs: getLogs,
getLogStream: getLogStream,
sendTestMail: sendTestMail
getLogStream: getLogStream
};
var appstore = require('../appstore.js'),
@@ -32,7 +31,6 @@ var appstore = require('../appstore.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
progress = require('../progress.js'),
mailer = require('../mailer.js'),
superagent = require('superagent'),
updateChecker = require('../updatechecker.js'),
_ = require('underscore');
@@ -302,13 +300,3 @@ function getLogStream(req, res, next) {
logStream.on('error', res.end.bind(res, null));
});
}
function sendTestMail(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.email || typeof req.body.email !== 'string') return next(new HttpError(400, 'email must be a non-empty string'));
mailer.sendTestMail(req.body.email);
next(new HttpSuccess(202));
}
+17 -1
View File
@@ -8,7 +8,9 @@ exports = module.exports = {
setMailFromValidation: setMailFromValidation,
setCatchAllAddress: setCatchAllAddress,
setMailRelay: setMailRelay,
setMailEnabled: setMailEnabled
setMailEnabled: setMailEnabled,
sendTestMail: sendTestMail
};
var assert = require('assert'),
@@ -106,3 +108,17 @@ function setMailEnabled(req, res, next) {
next(new HttpSuccess(202));
});
}
function sendTestMail(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
assert.strictEqual(typeof req.body, 'object');
if (!req.body.to || typeof req.body.to !== 'string') return next(new HttpError(400, 'to must be a non-empty string'));
mail.sendTestMail(req.params.domain, req.body.to, function (error) {
if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202));
});
}