2014-06-03 17:05:25 +04:00
|
|
|
// # Mail API
|
|
|
|
// API for sending Mail
|
2014-05-09 14:11:29 +04:00
|
|
|
var when = require("when"),
|
|
|
|
config = require('../config'),
|
2014-05-09 03:12:18 +04:00
|
|
|
errors = require('../errors'),
|
2014-04-04 05:59:09 +04:00
|
|
|
mail;
|
2014-05-09 03:12:18 +04:00
|
|
|
|
2014-06-03 17:05:25 +04:00
|
|
|
/**
|
|
|
|
* ## Mail API Methods
|
|
|
|
*
|
|
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
|
|
* @typedef Mail
|
|
|
|
* @param mail
|
|
|
|
*/
|
2014-04-04 05:59:09 +04:00
|
|
|
mail = {
|
2014-06-03 17:05:25 +04:00
|
|
|
/**
|
|
|
|
* ### Send
|
|
|
|
* Send an email
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @param {Mail} object details of the email to send
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
send: function (object) {
|
2014-05-09 03:12:18 +04:00
|
|
|
var mailer = require('../mail');
|
|
|
|
|
2014-06-03 17:05:25 +04:00
|
|
|
// TODO: permissions
|
|
|
|
return mailer.send(object.mail[0].message)
|
2014-04-04 05:59:09 +04:00
|
|
|
.then(function (data) {
|
2014-06-03 17:05:25 +04:00
|
|
|
delete object.mail[0].options;
|
2014-06-03 15:31:14 +04:00
|
|
|
// Sendmail returns extra details we don't need and that don't convert to JSON
|
2014-06-03 17:05:25 +04:00
|
|
|
delete object.mail[0].message.transport;
|
|
|
|
object.mail[0].status = {
|
2014-05-09 03:12:18 +04:00
|
|
|
message: data.message
|
|
|
|
};
|
2014-06-03 17:05:25 +04:00
|
|
|
return object;
|
2014-04-04 05:59:09 +04:00
|
|
|
})
|
|
|
|
.otherwise(function (error) {
|
2014-05-09 14:11:29 +04:00
|
|
|
return when.reject(new errors.EmailError(error.message));
|
2014-04-04 05:59:09 +04:00
|
|
|
});
|
|
|
|
},
|
2014-06-03 17:05:25 +04:00
|
|
|
/**
|
|
|
|
* ### SendTest
|
|
|
|
* Send a test email
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2014-04-04 05:59:09 +04:00
|
|
|
sendTest: function () {
|
2014-06-03 15:31:14 +04:00
|
|
|
var 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>',
|
2014-05-09 03:12:18 +04:00
|
|
|
|
2014-06-03 15:31:14 +04:00
|
|
|
payload = {mail: [{
|
|
|
|
message: {
|
|
|
|
subject: 'Test Ghost Email',
|
|
|
|
html: html
|
|
|
|
}
|
|
|
|
}]};
|
2014-05-09 03:12:18 +04:00
|
|
|
|
2014-06-03 15:31:14 +04:00
|
|
|
return mail.send(payload);
|
2014-04-04 05:59:09 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
module.exports = mail;
|