Merge pull request #3129 from jaswilli/issue-3071

Fix mail test send endpoint
This commit is contained in:
Hannah Wolfe 2014-06-27 22:07:13 +01:00
commit 1b21a42b48
2 changed files with 17 additions and 3 deletions

View File

@ -1,6 +1,6 @@
// # Mail API
// API for sending Mail
var when = require("when"),
var when = require('when'),
config = require('../config'),
errors = require('../errors'),
mail;
@ -39,14 +39,16 @@ mail = {
return when.reject(new errors.EmailError(error.message));
});
},
/**
* ### SendTest
* Send a test email
*
* @public
* @param {Object} required property 'to' which contains the recipient address
* @returns {Promise}
*/
sendTest: function () {
sendTest: function (object) {
var html = '<p><strong>Hello there!</strong></p>' +
'<p>Excellent!' +
' You\'ve successfully setup your email config for your Ghost blog over on ' + config().url + '</p>' +
@ -57,6 +59,7 @@ mail = {
payload = {mail: [{
message: {
to: object.to,
subject: 'Test Ghost Email',
html: html
}
@ -65,4 +68,5 @@ mail = {
return mail.send(payload);
}
};
module.exports = mail;

View File

@ -39,7 +39,17 @@ apiRoutes = function (middleware) {
router['delete']('/ghost/api/v0.1/db/', api.http(api.db.deleteAllContent));
// ## Mail
router.post('/ghost/api/v0.1/mail', api.http(api.mail.send));
router.post('/ghost/api/v0.1/mail/test', api.http(api.mail.sendTest));
router.post('/ghost/api/v0.1/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);
});
});
// ## Slugs
router.get('/ghost/api/v0.1/slugs/:type/:name', api.http(api.slugs.generate));
// ## Authentication