Merge pull request #3704 from javorszky/iss3649

Sends test email to the person who clicked on the button
This commit is contained in:
Hannah Wolfe 2014-08-08 22:54:21 +01:00
commit 2472637321
2 changed files with 17 additions and 21 deletions

View File

@ -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'));
});
},

View File

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