0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/api/mail.js
Sebastian Gierlinger 39e654e9c3 Change error message response
closes #2643
- added error type
- added error property for validations
- wrapped errors in an array
- returns multiple errors for validation
- updated tests and admin
2014-05-05 15:51:21 +02:00

44 lines
No EOL
1.5 KiB
JavaScript

var when = require("when"),
config = require('../config'),
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({type: 'EmailError', message: error.message });
});
},
// #### SendTest
// **takes:** nothing
sendTest: function () {
// **returns:** a promise
return mail.send({
subject: 'Test Ghost Email',
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>' +
'<p>If you hadn\'t, you wouldn\'t be reading this email, but you are, so it looks like all is well :)</p>' +
'<p>xoxo</p>' +
'<p>Team Ghost<br>' +
'<a href="https://ghost.org">https://ghost.org</a></p>'
});
}
};
module.exports = mail;