var when = require("when"), config = require('../config'), errors = require('../errors'), mail; // ## Mail mail = { // #### Send // **takes:** a json object representing an email. send: function (postData) { var mailer = require('../mail'), message = { to: postData.to, subject: postData.subject, html: postData.html }; // **returns:** a promise from the mailer with the number of successfully sent emails return mailer.send(message) .then(function (data) { return when.resolve({message: data.message }); }) .otherwise(function (error) { return when.reject(new errors.EmailError(error.message)); }); }, // #### SendTest // **takes:** nothing sendTest: function () { // **returns:** a promise return mail.send({ subject: 'Test Ghost Email', html: '

Hello there!

' + '

Excellent! You\'ve successfully setup your email config for your Ghost blog over on ' + config().url + '

' + '

If you hadn\'t, you wouldn\'t be reading this email, but you are, so it looks like all is well :)

' + '

xoxo

' + '

Team Ghost
' + 'https://ghost.org

' }); } }; module.exports = mail;