Coder Social home page Coder Social logo

sailscastshq / sails-hook-mail Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 2.0 67 KB

The simple elegant way to send emails from a Sails application

Home Page: https://docs.sailscasts.com/mail

License: MIT License

JavaScript 98.63% Shell 1.37%
nodemailer resend resend-email sails-hook sailsjs smtp transactional-emails

sails-hook-mail's Introduction

Mail

The simple elegant way to send emails from a Sails application

Getting Started

npm i sails-hook-mail --save

Usage

In your Sails action you can use the send helper like so:

await sails.helpers.mail.send.with({
  subject: 'Verify your email',
  template: 'email-verify-account',
  to: user.email,
  templateData: {
    token: user.emailProofToken,
    fullName: user.fullName
  }
})

Mailers

Mail supports a couple of mailers including:

  • log
  • SMTP

To use Mail, create a config/mail.js and specify your default mailer as well as the mailers you'd like to support in your Sails application like so:

module.exports.mail = {
  default: process.env.MAIL_MAILER || 'log',
  mailers: {
    smtp: {
      transport: 'smtp'
    },
    log: {
      transport: 'log'
    }
  },
  from: {
    address: process.env.MAIL_FROM_ADDRESS || '[email protected]',
    name: process.env.MAIL_FROM_NAME || 'The Boring JavaScript Stack'
  }
}

log

To use the log mailer, set the default property of config/mail.js to log and make sure you have a log mailer under the mailers object.

Sails will log your email to the console

SMTP

To use SMTP as a mailer set it as the default in config/mail.js and also install the peer dependency nodemailer:

npm i nodemailer --save

Then in your config/local.js you can provide the SMTP credentials like so:

// config/local.js
smtp: {
  host: 'HOST',
  username: 'USERNAME',
  password: 'PASSWORD'
}

sails-hook-mail's People

Contributors

dominuskelvin avatar lennyaiko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sails-hook-mail's Issues

Make configuration in local.js match config/mail.js

Since configs in locals.js gets merged into other configs, it makes more sense not to deviate from how mailers are being configured in config/mail.js. Currently we have:

mailer: 'nodemailer',
mailer: {
   nodemailer: {}
}

But we can however follow same configuration signature in config/mail.js and eliminate the checks in getting what mailer to use in production or development all together. With this change setting up an email mailer in local will look similar to that in config/mails.js.

mail: {
 default: 'nodemailer',
 mailers: {
    nodemailer: {}
}
}

This simplifies things.

  • update code to reflect this decision
  • update docs

Fix fetching 'from address'

A typo was noticed when sails-hook-mail tries to fetch the from address in the user's env file.

What is:
process.env.MAIL_FROM_ADRESS

What should be:
process.env.MAIL_FROM_ADDRESS

A repeat of typo fix in send.js file

Currently:

 from: {
      description:
        'An override for the default "from" email that\'s been configured.',
      example: '[email protected]',
      isEmail: true,
      defaultsTo: process.env.MAIL_FROM_ADRESS || sails.config.mail.from.address
    },

Should be:

 from: {
      description:
        'An override for the default "from" email that\'s been configured.',
      example: '[email protected]',
      isEmail: true,
      defaultsTo: process.env.MAIL_FROM_ADDRESS || sails.config.mail.from.address
    },

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.