fd0f5a5028
closes #2690 - added new error classes - moved errorhandling.js to /errors/index.js - changed API errors to use new classes - updated tests
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
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: '<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; |