From 91a0c7c666985947b74aab5dfd1d4c28733c0220 Mon Sep 17 00:00:00 2001 From: Peter Szel Date: Fri, 4 Apr 2014 03:59:09 +0200 Subject: [PATCH] Added email sending endpoint to the API. closes #2550 - Added new API module named 'mail' - Added routes for the mail endpoint - Added 'send a test email' button to the debug settigns page - Added handler to this button which sends and AJAX request to the mail API endpoint --- ghost/admin/views/debug.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/ghost/admin/views/debug.js b/ghost/admin/views/debug.js index e08e2b5c8a..e3333a15d4 100644 --- a/ghost/admin/views/debug.js +++ b/ghost/admin/views/debug.js @@ -6,7 +6,8 @@ events: { "click .settings-menu a": "handleMenuClick", "click #startupload": "handleUploadClick", - "click .js-delete": "handleDeleteClick" + "click .js-delete": "handleDeleteClick", + "click #sendtestmail": "handleSendTestMailClick" }, initialize: function () { @@ -154,6 +155,35 @@ } } })); - } + }, + + handleSendTestMailClick: function (ev) { + ev.preventDefault(); + + $.ajax({ + url: Ghost.paths.apiRoot + '/mail/test/', + type: 'POST', + headers: { + 'X-CSRF-Token': $("meta[name='csrf-param']").attr('content') + }, + success: function onSuccess(response) { + Ghost.notifications.addItem({ + type: 'success', + message: ['Check your email for the test message: ', response.message].join(''), + status: 'passive' + }); + }, + error: function onError(response) { + var responseText = JSON.parse(response.responseText), + message = responseText && responseText.error ? responseText.error : 'unknown'; + Ghost.notifications.addItem({ + type: 'error', + message: ['A problem was encountered while sending the test email: ', message].join(''), + status: 'passive' + }); + + } + }); + }, }); }());