1.0.2 • Published 9 years ago

sails-hook-mailin v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

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

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.11.5

9 years ago