Giter Site home page Giter Site logo

adapt-authoring-mailer's People

Contributors

iklemm avatar taylortom avatar tomgreenfield avatar

Watchers

 avatar  avatar

adapt-authoring-mailer's Issues

Can we refactor send to return the same data as nodemailer .sendMail

May be useful...

Can we also refactor this a bit to return early (and throw errors as it's async), the code's a bit difficult to follow by eye in its current form - something like:

(in fact the first check shouldn't be needed, as the module shouldn't initialise if it's not been enabled)

async send(to, subject, text, html) {
    if (!this.useSmtp || !this.isConfigValid || !this.transporter) {
      throw new Error(this.app.lang.t("info.smtpNotEnabled"));
    }
    if (!this.isConnectionVerified) {
      // connection not tested before, should we do testConnection() here before sending?
    }
    if (!MailerUtils.isValidEmail(to)) {
      throw new Error(this.app.lang.t("error.smptEmailValidationFailed", {email: to}));
    }
    try {
      const info = await this.transporter.sendMail({to, subject, text, html});
      this.log('info', `${this.app.lang.t('info.sentSuccessfully')} ${info.response}`);
      return info;
    } catch(e) {
      this.log('error', 'error.sendFailed');
      throw this.formatError('sendFailed', e);
    }
  }

Typos in lang strings

  • smptUrlValidationFailed: string should be Validation of smtp connection parameters failed.
  • smptEmailValidationFailed: key should be smtpEmailValidationFailed
  • smptUrlValidationFailed: key should be smtpUrlValidationFailed
  • smptParamsValidationFailed: key should be smtpParamsValidationFailed

Should we remove config options?

I'm thinking it may be a bit less hassle to remove all SMTP connection config options except connectionUrl (to cut down on the logic that's needed in mailer)

isReady override can be moved to init

I'd generally advise against overriding setReady. It's fine to add the logic to the bottom of init, then calling isReady:

 async init() {
    this.isConfigValid = false;
    this.isConnectionVerified = false;
    await this.readConfig();
    if (this.useSmtp) this.createTransporter();
    
    if (this.useSmtp && this.isConfigValid && this.transporter) {
      this.log('debug', this.app.lang.t("info.smtpOk"));
    } else {
      this.log('debug', this.app.lang.t("info.smtpNotEnabled"));
    }
    this.setReady();
  }

As a side-note: if you're overriding another function, it's best to call the super function directly rather than copying the behaviour (obviously if you want to modify the super behaviour, that's fine):

function isReady() {
   // ... my custom code
  super.isReady(); // or other way of calling depending on what you're doing, i.e. super.isReady.apply(scope, args)
}

Rename useSmtp config option

I think just calling this enable works better, and fits with some of the options in other modules.

Would also be nice to return really early is enable is false (maybe have the check here)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.