1.0.0 • Published 7 years ago

@grupojaque/mailer-jaque v1.0.0

Weekly downloads
59
License
MIT
Repository
gitlab
Last release
7 years ago

Mailer Jaque

Module for sending mails from an ejs template.

pipeline status coverage report

Setup

Requirements

Modules
  • Nodemailer: Used for sending the mail.
  • Ejs: Used for rendering the templates.

Initialization

Install with;

$ npm install mailer-jaque

Import in project.

const configObject = require('path/to/config.js');\ const mailer = require('mailer-jaque')(configObject);

Configuration

Configuration values

The module needs the transport information in the configuration.

KeyDescriptionExample
transport.hostName of the email server to use'smtp.ethereal.email'
transport.portPort to connect to transport.host587
transport.auth.userEmail user to use in he authentication'iq3i4rreg4tnevnq@ethereal.email'
transport.auth.passEmail password to use in he authentication'DejVytmSpYGrn52fEM'
viewsDirRelative route to the views to use (from the project root)'views'
templates.template_name.viewName of the ejs file associated to the template template_name'test'
templates.template_name.subjectSubject to be used in the mail'Company name - Formal subject'
fromRemitent to be used in the email, this is a default and will be overwritten if this field is present in the mail options'David Plowie'
testModeif true it will deactivate the mailing for testing purposesfalse

You can find a configuration example file here

Usage

send(options)

Will send an email.

  • options: Object containing the values to be used in the ejs rendering destinatary and html code or the name of the template to use. Optionally the Name of the remitent, and subject. Examples:
    {
      to: 'user@mail.com',
      template: 'test',
      data: { // Values to be used in the ejs rendering
        user: {
          name: 'Ayrton',
        },
        secret_token: 'czxcsdhsgrwgg43twf'
      }
    }
    {
     to: 'user@mail.com',
     from: 'Me',
     html: '<p> Hello there!</p>',
     subject: 'Hello'
    }

Errors

Errors will be instances of MailerError, wich extends the Error class

statusmessagedescription
500serverErrorCant send mail without to
500serverErrorTamplate not found

Contributors

  • Emilio Martínez