sails-hook-mailin

1.0.2 • Public • Published

This provides a sails hook integrating Mailin within your app. Mailin is an smtp server that listens for emails and parses them as json.

NPM version Dependency status

Install

$ npm install sails-hook-mailin --save

Usage

1. configure .sailsrc

{
  "generators": {
    "modules": {
      "mailin-api": "sails-hook-mailin/generator"
    }
  }
}

2. install sails.js extension

$ sails generate mailin-api

This create the Mailin Service event handler, and config. The default service name is MailinService, to use a different name instead use

$ sails generate mailin-api MyCustomMailinService

Configuration

Simply modify the generated config/mailin.js to modify the options

module.exports.mailin = {
  // Enable/Disable mail server
    enable: true,
    
    // Mail Port
    port: 2500,
    
    // Service to handle incoming mail 
    handlerService: MailinService
}

Service Handler

Modify generated service handle, add methods for events you want to listen for

// api/services/MailinService.js
module.exports = {
 
  // Validate email recipient
  validateRecipient: function (connection, email, callback) {
    if(email != "dprietti@test.com") return callback(new Error("Invalid Recipient"));
 
    callback();
  },
 
 
  // Message was received and parsed.
  message: function (connection, data, content) {
    console.log("New Message Received - Subject: " + data.subject);
  }
 
};

For all possible event methods, see Mailin Events

Readme

Keywords

none

Package Sidebar

Install

npm i sails-hook-mailin

Weekly Downloads

0

Version

1.0.2

License

ISC

Last publish

Collaborators

  • dprietti