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

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));
});
}