epochtalk-emailer

0.0.2 • Public • Published

Emailer

Email server for EpochTalk Frontend.

Installation and Configuration

  1. Checkout repository using git:
$ git clone git@github.com:epochtalk/emailer.git
  1. Change directories and install dependencies using npm
cd emailer
$ npm install
  1. Add and set the following configs to a .env file.
SMTP_HOST=smtp.example.com
SMTP_USER=info@example.com
SMTP_PASS=password
  1. Run the server using foreman
$ foreman start -f Profile

Adding Templates

  • Create an html template using doT notation for parameters
  • Place html file in /templates folder
  • Add export for new template to emails.js

Example

Add Template File (templates/recover-account.html)

  <h3>Account Recovery</h3>
  Recover your account by visiting the link below and resetting your password:<br /><br />
  <strong>Username</strong>: {{=it.username}}<br />
  <strong>Password</strong>:
  <a href="{{=it.resetUrl}}">Reset</a>

Add Template Export to email.js

exports.recoverAccount = {
  schema: {
    username: joi.string().min(1).max(255).required(),
    reset_url: joi.string().required(),
    email: joi.string().email().required()
  },
  compile: function(params) {
    var template = doT.template(templateFile('recover-account.html'));
    return {
      from: config.senderEmail,
      to: params.email,
      subject: '[EpochTalk] Account Recovery',
      html: template({ username: params.username, resetUrl: params.reset_url })
    };
  }
};
  • schema - validation schema for email template params
  • compile - returns email object with compiled template

Call Server

Call the emailer server using a library that supports unix domain sockets like request.

var request = require('request');
 
var params = {
  username: 'john',
  email: 'john@example.com',
  reset_url: 'http://localhost:8080/reset/john/123412412412412',
};
 
request.post({ url:'http://unix:/tmp/epochEmailer.sock:/recoverAccount', formData: params }, function(err, res, body) {
  if (body.statusCode === 200) {
    console.log(body.message); // success
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i epochtalk-emailer

Weekly Downloads

3

Version

0.0.2

License

MIT

Last publish

Collaborators

  • wangbus