2014-05-09 05:11:29 -05:00
|
|
|
var when = require("when"),
|
|
|
|
config = require('../config'),
|
2014-05-08 18:12:18 -05:00
|
|
|
errors = require('../errors'),
|
2014-04-03 20:59:09 -05:00
|
|
|
mail;
|
2014-05-08 18:12:18 -05:00
|
|
|
|
2014-04-03 20:59:09 -05:00
|
|
|
// ## Mail
|
|
|
|
mail = {
|
|
|
|
|
|
|
|
// #### Send
|
|
|
|
// **takes:** a json object representing an email.
|
|
|
|
send: function (postData) {
|
2014-05-08 18:12:18 -05:00
|
|
|
var mailer = require('../mail');
|
|
|
|
|
2014-04-03 20:59:09 -05:00
|
|
|
// **returns:** a promise from the mailer with the number of successfully sent emails
|
2014-05-08 18:12:18 -05:00
|
|
|
return mailer.send(postData.mail[0].message)
|
2014-04-03 20:59:09 -05:00
|
|
|
.then(function (data) {
|
2014-05-08 18:12:18 -05:00
|
|
|
delete postData.mail[0].options;
|
|
|
|
postData.mail[0].status = {
|
|
|
|
message: data.message
|
|
|
|
};
|
|
|
|
return postData;
|
2014-04-03 20:59:09 -05:00
|
|
|
})
|
|
|
|
.otherwise(function (error) {
|
2014-05-09 05:11:29 -05:00
|
|
|
return when.reject(new errors.EmailError(error.message));
|
2014-04-03 20:59:09 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
// #### SendTest
|
|
|
|
// **takes:** nothing
|
|
|
|
sendTest: function () {
|
|
|
|
// **returns:** a promise
|
2014-05-08 18:12:18 -05:00
|
|
|
|
|
|
|
|
2014-04-03 20:59:09 -05:00
|
|
|
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;
|