mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Added initial bulk-email service
no-issue This is a simple wrapper around the current ghost mailer service for now
This commit is contained in:
parent
a30caa5c66
commit
20ce0c313c
1 changed files with 36 additions and 0 deletions
36
core/server/services/bulk-email/index.js
Normal file
36
core/server/services/bulk-email/index.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
// @ts-check
|
||||
const mailService = require('../mail');
|
||||
const ghostMailer = new mailService.GhostMailer();
|
||||
|
||||
/*
|
||||
* An email address
|
||||
* @typedef { string } EmailAddress
|
||||
*/
|
||||
|
||||
/*
|
||||
* An object representing an email to send
|
||||
* @typedef { Object } Email
|
||||
* @property { string } html - The html content of the email
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* @param {Email} message - The message to send
|
||||
* @param {[EmailAddress]} recipients - the recipients to send the email to
|
||||
* @returns {Promise<boolean>} A promise representing the success of the email sending
|
||||
*/
|
||||
async send(message, recipients) {
|
||||
for (const recipient in recipients) {
|
||||
const messageToSend = Object.assign({}, message, {
|
||||
to: recipient
|
||||
});
|
||||
try {
|
||||
await ghostMailer.send(messageToSend);
|
||||
} catch (err) {
|
||||
// @TODO log this somewhere with state?
|
||||
console.log(`Oh no! an email failed to send :( ${recipient}`);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue