sails-hook-mailin
v1.0.2
Published
Sails hook for embedding an SMTP mail server
Downloads
5
Readme
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][npm-image]][npm-url] [![Dependency status][david-dm-image]][david-dm-url] [npm-url]: https://npmjs.org/package/sails-hook-mailin [npm-image]: http://img.shields.io/npm/v/sails-hook-mailin.svg [david-dm-url]:https://david-dm.org/dapriett/sails-hook-mailin [david-dm-image]:https://david-dm.org/dapriett/sails-hook-mailin.svg
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 != "[email protected]") 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