-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e757b6f
commit 9e3fb59
Showing
9 changed files
with
252 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const request = require('request-promise-native'); | ||
|
||
const config = require('../config'); | ||
|
||
/** | ||
* @param {Object} options | ||
* @param {string|string[]} options.to | ||
* @param {string} options.template | ||
* @param {string} options.subject | ||
* @param {object} options.reply_to | ||
* @param {object} options.parameters | ||
*/ | ||
module.exports.sendMail = async (options) => { | ||
const mailerBody = await request({ | ||
url: config.mailer.url + ':' + config.mailer.port + '/', | ||
method: 'POST', | ||
simple: false, | ||
json: true, | ||
body: { | ||
to: options.to, | ||
subject: options.subject, | ||
template: options.template, | ||
parameters: options.parameters, | ||
reply_to: options.reply_to | ||
} | ||
}); | ||
|
||
if (typeof mailerBody !== 'object') { | ||
throw new Error('Malformed response from mailer: ' + mailerBody); | ||
} | ||
|
||
if (!mailerBody.success) { | ||
throw new Error('Unsuccessful response from mailer: ' + JSON.stringify(mailerBody)); | ||
} | ||
|
||
return mailerBody; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.