1.0.2 • Published 10 years ago
sails-hook-mailin v1.0.2
This provides a sails hook integrating Mailin within your app. Mailin is an smtp server that listens for emails and parses them as json.
Install
$ npm install sails-hook-mailin --saveUsage
1. configure .sailsrc
{
  "generators": {
    "modules": {
      "mailin-api": "sails-hook-mailin/generator"
    }
  }
}2. install sails.js extension
$ sails generate mailin-apiThis 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 MyCustomMailinServiceConfiguration
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