mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 01:03:23 +03:00
57a5b6a188
closes #2622, ref #2125
68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
// # Mail API
|
|
// API for sending Mail
|
|
var when = require("when"),
|
|
config = require('../config'),
|
|
errors = require('../errors'),
|
|
mail;
|
|
|
|
/**
|
|
* ## Mail API Methods
|
|
*
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
* @typedef Mail
|
|
* @param mail
|
|
*/
|
|
mail = {
|
|
/**
|
|
* ### Send
|
|
* Send an email
|
|
*
|
|
* @public
|
|
* @param {Mail} object details of the email to send
|
|
* @returns {Promise}
|
|
*/
|
|
send: function (object) {
|
|
var mailer = require('../mail');
|
|
|
|
// TODO: permissions
|
|
return mailer.send(object.mail[0].message)
|
|
.then(function (data) {
|
|
delete object.mail[0].options;
|
|
// Sendmail returns extra details we don't need and that don't convert to JSON
|
|
delete object.mail[0].message.transport;
|
|
object.mail[0].status = {
|
|
message: data.message
|
|
};
|
|
return object;
|
|
})
|
|
.otherwise(function (error) {
|
|
return when.reject(new errors.EmailError(error.message));
|
|
});
|
|
},
|
|
/**
|
|
* ### SendTest
|
|
* Send a test email
|
|
*
|
|
* @public
|
|
* @returns {Promise}
|
|
*/
|
|
sendTest: function () {
|
|
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>',
|
|
|
|
payload = {mail: [{
|
|
message: {
|
|
subject: 'Test Ghost Email',
|
|
html: html
|
|
}
|
|
}]};
|
|
|
|
return mail.send(payload);
|
|
}
|
|
};
|
|
module.exports = mail; |