index.js 868 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. const coreClass = require("../../core");
  3. const config = require('config');
  4. let mailgun = null;
  5. module.exports = class extends coreClass {
  6. initialize() {
  7. return new Promise((resolve, reject) => {
  8. this.setStage(1);
  9. this.schemas = {
  10. verifyEmail: require('./schemas/verifyEmail'),
  11. resetPasswordRequest: require('./schemas/resetPasswordRequest'),
  12. passwordRequest: require('./schemas/passwordRequest')
  13. };
  14. this.enabled = config.get('apis.mailgun.enabled');
  15. if (this.enabled)
  16. mailgun = require('mailgun-js')({
  17. apiKey: config.get("apis.mailgun.key"),
  18. domain: config.get("apis.mailgun.domain")
  19. });
  20. resolve();
  21. });
  22. }
  23. async sendMail(data, cb) {
  24. try { await this._validateHook(); } catch { return; }
  25. if (!cb) cb = ()=>{};
  26. if (this.enabled) mailgun.messages().send(data, cb);
  27. else cb();
  28. }
  29. }