lockit-sendmail

1.1.2 • Public • Published

Lockit sendmail

Build Status NPM version

Email utilities for Lockit.

Installation

npm install lockit-sendmail

var Email = require('lockit-sendmail');
var config = require('./config.js');
 
var email = new Email(config);
 
email.signup('john', 'john@wayne.com', 'secret-token', function(err, res) {
  // res is the same res you would get from nodemailer
  // for more infos see https://github.com/andris9/Nodemailer#return-callback
})

Configuration

Add credentials to your config.js. This module uses nodemailer for sending emails. You can therefore use the same email types and email settings.

exports.emailType = 'SMTP';
exports.emailSettings = {
  service: 'Gmail',
  auth: {
    user: 'john.wayne@gmail.com',
    pass: 'cowboy'
  }
};

Methods

Verify email address

A new user has signed up and his email address needs to be verified. An email with a link containing a unique token is sent to his email address. When the user clicks on this link we know that the given email address exists und belongs to the right user.

email.signup('john', 'john@wayne.com', 'abc-123-def', function(err, res) {
  if (err) console.log(err);
  // ...
})

You can configure the email's content through your config.js. Just modify the emailSignup object. Here is a sample setup.

exports.emailSignup = {
  subject: 'Welcome to <%- appname %>',
  text: [
    '<h2>Hello <%- username %></h2>',
    'Welcome to <%- appname %>!',
    '<p><%- link %> to complete your registration.</p>'
  ].join(''),
  linkText: 'Click here'
};
  • subject - the email's subject
  • text - the email's body
  • linkText - the text of the link, which points back to our app

Duplicate email tries to sign up

A user tries to sign up with an email address that already exists. We send a hint to the right owner to indicate this happening. Never expose to a user whether an email address exists or not.

email.taken('john', 'john@wayne.com', function(err, res) {
  if (err) console.log(err);
  // ...
})

You can configure the email's content through your config.js. Just modify the emailSignupTaken object. Here is a sample setup.

exports.emailSignupTaken = {
  subject: 'Email already registered',
  text: [
    '<h2>Hello <%- username %></h2>',
    'you or someone else tried to sign up for <%- appname %>.',
    '<p>Your email is already registered and you cannot sign up twice.',
    ' If you haven\'t tried to sign up, you can safely ignore this email. Everything is fine!</p>',
    '<p>The <%- appname %> Team</p>'
  ].join('')
};
  • subject - the email's subject
  • text - the email's body

Send email address verification link again

A user signed up but lost or didn't receive the email containing the link for his email address verification. Therefore he should be able to send the link again, with a different verification token.

email.resend('john', 'john@wayne.com', 'abc-123-def', function(err, res) {
  if (err) console.log(err);
  // ...
})

You can configure the email's content through your config.js. Just modify the emailResendVerification object. Here is a sample setup.

exports.emailResendVerification = {
  subject: 'Complete your registration',
  text: [
    '<h2>Hello <%- username %></h2>',
    'here is the link again. <%- link %> to complete your registration.',
    '<p>The <%- appname %> Team</p>'
  ].join(''),
  linkText: 'Click here'
};
  • subject - the email's subject
  • text - the email's body
  • linkText - the text of the link, which points back to our app

Forgot password email

A user has forgotten his password and would like to create a new one. He enters his email address and an email with a link containing a secret token is sent to his email address.

email.forgot('john', 'john@wayne.com', 'abc-123-def', function(err, res) {
  if (err) console.log(err);
  // ...
})

You can configure the email's content through your config.js. Just modify the emailForgotPassword object. Here is a sample setup.

exports.emailForgotPassword = {
  subject: 'Reset your password',
  text: [
    '<h2>Hey <%- username %></h2>',
    '<%- link %> to reset your password.',
    '<p>The <%- appname %> Team</p>'
  ].join(''),
  linkText: 'Click here'
};
  • subject - the email's subject
  • text - the email's body
  • linkText - the text of the link, which points back to our app

Test

$ npm test

License

MIT

Package Sidebar

Install

npm i lockit-sendmail

Weekly Downloads

15

Version

1.1.2

License

MIT

Last publish

Collaborators

  • zemirco