Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SendgridService {
- constructor(config) {
- this.client = sendgrid(config.sendgrid.api_key);
- }
- send(options) {
- return new Promise((resolve, reject) => {
- this.client.send(options, function(error, result) {
- if (error) {
- console.error("(send) Failure - Message: %j Error: %j", options, error);
- return reject(error);
- }
- console.log("(send) Success - Message: %j Result: %j", options, result);
- return resolve(result);
- });
- });
- }
- }
- class EmailService {
- constructor(options, config = Config) {
- this.config = config;
- this.provider = new Sendgrid(options, config);
- }
- send(options, record_info) {
- if (_.contains([ "sandbox", "dev" ], this.config.env.name)) {
- options.to = this.config.email.test_recipient;
- options.bcc = undefined;
- // other test related stuff
- }
- console.log("Sending email from: %s to: %s", options.from, options.to);
- return this.provider.send(options)
- .then(result => {
- // some log/operation in case of success
- return result;
- })
- .catch(error => {
- // some log/operation in case of error, can be fallback or retry
- return Promise.reject(error);
- });
- }
- };
Add Comment
Please, Sign In to add comment