Skip to content

Getting started

Introduction

Mail or Sails Mail provides a sleek, elegant, and developer-friendly email API that turns sending emails into a walk in the park for your Sails applications.

Mail introduces transports for sending emails via SMTP, Resend, etc which allows you to quickly and elegantly get started sending emails through any local or cloud-based email service of your choice.

Installation

Prerequisites

To install Mail, simply run the following command in your Sails project:

sh
$ npm install sails-hook-mail

Usage

Mail exposes a send helper that you can call in your Sails actions or where ever you have access to helpers in your Sails application.

For example we can send an email verification email when a user signs up successfully via a user/signup.js action:

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

You can already see a couple of the arguments you can pass to the send helper provided by Mail.

Next, You can check out all the various supported transports Mail provide for you to send your emails and how to configure them

All open source projects are released under the MIT License.