diff --git a/core/server/api/mail.js b/core/server/api/mail.js index c5614ecd85..88f05b785b 100644 --- a/core/server/api/mail.js +++ b/core/server/api/mail.js @@ -58,19 +58,23 @@ mail = { * @param {Object} required property 'to' which contains the recipient address * @returns {Promise} */ - sendTest: function (object, options) { + sendTest: function (options) { + var user = require('../models/user').User; - return mail.generateContent({template: 'test'}).then(function (emailContent) { - var payload = {mail: [{ - message: { - to: object.to, - subject: 'Test Ghost Email', - html: emailContent.html, - text: emailContent.text - } - }]}; - - return mail.send(payload, options); + return user.findOne({id: options.context.user}).then(function (result) { + return mail.generateContent({template: 'test'}).then(function (emailContent) { + var payload = {mail: [{ + message: { + to: result.get('email'), + subject: 'Test Ghost Email', + html: emailContent.html, + text: emailContent.text + } + }]}; + return mail.send(payload, options); + }); + }, function () { + return when.reject(new errors.NotFoundError('Could not find the current user')); }); }, diff --git a/core/server/routes/api.js b/core/server/routes/api.js index cf4335ebc0..67a60150cf 100644 --- a/core/server/routes/api.js +++ b/core/server/routes/api.js @@ -58,15 +58,7 @@ apiRoutes = function (middleware) { // ## Mail router.post('/mail', api.http(api.mail.send)); router.post('/mail/test', function (req, res) { - api.settings.read('email').then(function (result) { - // attach the to: address to the request body so that it is available - // to the http api handler - req.body = { to: result.settings[0].value }; - - api.http(api.mail.sendTest)(req, res); - }).catch(function () { - api.http(api.mail.sendTest)(req, res); - }); + api.http(api.mail.sendTest)(req, res); });