mirror of
https://github.com/balkian/Hookio-Mailer.git
synced 2025-09-02 10:32:19 +00:00
First Commit
This commit is contained in:
57
lib/mailer.js
Normal file
57
lib/mailer.js
Normal file
@@ -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);
|
||||
|
||||
});
|
||||
|
||||
};
|
Reference in New Issue
Block a user