epochtalk-emailer
EpochTalk server for sending emails.
Last updated 5 years ago by wangbus .
MIT · Original npm · Tarball · package.json
$ cnpm install epochtalk-emailer 
SYNC missed versions from official npm registry.

#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
  }
});

Current Tags

  • 0.0.2                                ...           latest (5 years ago)

2 Versions

  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (0)
None
Dependents (2)

Copyright 2014 - 2016 © taobao.org |