lockit-sendmail

utilities for all the email communication from lockit

Lockit sendmail

Email utilities for Lockit.

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(errres) {
  // res is the same res you would get from nodemailer 
  // for more infos see https://github.com/andris9/Nodemailer#return-callback 
})

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'
  }
};

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(errres) {
  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

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(errres) {
  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

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(errres) {
  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

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(errres) {
  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

grunt

MIT