1
0
mirror of https://github.com/balkian/Hookio-Mailer.git synced 2024-11-22 06:22:30 +00:00
Hookio-Mailer/lib/mailer.js
J.Fernando Sánchez 16a5c27759 First Commit
2012-02-22 13:11:54 +01:00

58 lines
1.3 KiB
JavaScript

// 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);
});
};