commit 16a5c277592960a3413cc1ce0664b194d64e75e5 Author: J.Fernando Sánchez Date: Wed Feb 22 13:11:54 2012 +0100 First Commit diff --git a/bin/mailer b/bin/mailer new file mode 100644 index 0000000..67d544d --- /dev/null +++ b/bin/mailer @@ -0,0 +1,13 @@ +#!/usr/bin/env node + +var Hook = require('../lib/mailer').MailerHook; + +var hook = new Hook({ + name: "mailer" +}); + + +// Hook.start defaults to localhost +// it can accept dnode constructor options ( for remote connections ) +// these hooks can be started on diffirent machines / networks / devices +hook.start(); diff --git a/config.json_example b/config.json_example new file mode 100644 index 0000000..d578987 --- /dev/null +++ b/config.json_example @@ -0,0 +1,7 @@ +{ + "mailer": { + "host": "smtp.gmail.com", + "username": "BLABLA@gmail.com", + "password": "password" + } +} diff --git a/lib/mailer.js b/lib/mailer.js new file mode 100644 index 0000000..b83426e --- /dev/null +++ b/lib/mailer.js @@ -0,0 +1,57 @@ +// The modules this hook requires +var Hook = require('hook.io').Hook, + util = require('util'), + mailerModule = require('mailer'); + +// Things we need to access in different functions + +// Set up the hook, and export it at the same time +var MailerHook = exports.MailerHook = function(options) { + var self = this; + Hook.call(self, options); // Basic initializations + self.config.use('file', { file: './config.json'}); + + // Register callback for hook::ready event + self.on('hook::ready', function() { + // When hook is ready, register callbacks for boxcar events + self.on('*::send', function(data) { + self.send(data); + }); + }); + +}; + +// Set up inheritance from Hook +util.inherits(MailerHook, Hook); + +// Callbacks defined below + +MailerHook.prototype.send = function(options){ + + var self = this, + settings = self.config.get('mailer'); + + console.log("Settings: "+settings); + console.log("Options: "+options); + mailerModule.send({ + ssl: true, + to: options.to, + from: options.from, + host: settings.host, + authentication: 'login', + username: settings.username, + password: settings.password, + domain: settings.domain, + subject: options.subject, + body: options.body + }, + function(err, result){ + if(err){ + return self.emit('error', err); + } + + self.emit('emailSent', result); + + }); + +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..e8a4e9f --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "author": "J.Fernando Sánchez ", + "name": "hook.io-mailer", + "description": "Hook for mail integration", + "keywords" : [ "hook", "hook.io", "calendar" ], + "version": "0.0.1", + "bugs" : { "url" : "http://github.com/balkian" }, + "repository": { + "type": "git", + "url": "git://github.com/balkian/hookio-mailer.git" + }, + "bin": { + "hookio-calendar": "./bin/mailer" + }, + "main": "./lib/mailer", + "engines": { + "node": ">= v0.4.7" + }, + "dependencies": { + "hook.io" : "0.8.x" + }, + "devDependencies": {} +}