'use strict';
var doT = require('dot'),
	emailjs = require('emailjs');


var isObject = function (obj) {
	if (typeof obj !== 'object' || obj === null) {
		return false;
	}
	if (obj.length === undefined) {
		return true;
	}
	return false;
};

var accounts = {},
	templates = {};

var mailer = {};

var getCompiled = function (template) {
	var compiled = {},
		i;
	for (i in template) {
		compiled[i] = doT.template( template[i] );
	}
	return compiled;
};

var Template = function (template) {
	var self = this;
	this.src = template;
	this.compiled = getCompiled( template );
	this.getMessage = function (data) {
		var msg = {},
			i;
		for (i in template) {
			msg[i] = self.compiled[i]( data );
		}
		return msg;
	};
};




mailer.send = function (account, template, data, callback) {
	callback = callback || function () {};
	if (!account || typeof account !== 'string' || !accounts[account]) {
		return callback( 'invalid account' );
	}
	account = accounts[account];
	if (!template) {
		return callback( 'invalid template' );
	}
	if (typeof template === 'string') {
		template = templates[template].getMessage;
	} else if (!isObject( template )) {
		return callback( 'invalid template' );
	} else {
		template = new Template( template ).getMessage;
	}
	data = data || {};
	var message = template( data );

	account.server.send( message, callback );
};

mailer.addAccount = function (key, data) {
	accounts[key] = {
		src: data,
		server: emailjs.server.connect( data )
	};
};

mailer.addTemplate = function (key, template) {
	templates[key] = new Template( template );
};

mailer.getTemplate = function (key) {
	return templates[key].src;
};

mailer.removeTemplate = function (key) {
	delete templates[key];
};

module.exports = mailer;

@@ -65,16 +65,52 @@
 ljs');%0A%0A
+var accounts = %7B%7D,%0A%09templates = %7B%7D;%0A
 %0Avar isO
@@ -275,63 +275,8 @@
 %7D;%0A%0A
-var accounts = %7B%7D,%0A%09templates = %7B%7D;%0A%0Avar mailer = %7B%7D;%0A%0A
 var 
@@ -696,17 +696,282 @@
 %7D;%0A%7D;%0A%0A%0A
-%0A
+var mailer = %7B%7D;%0A%0A/**%0A * Send email%0A * @param  %7BString%7D   account  account key%0A * @param  %7BString%7CObject%7D   template template key or template object%0A * @param  %7BObject%7D   data     data for template rendering%0A * @param  %7BFunction%7D callback Signature: err, message%0A */
 %0Amailer.
@@ -1589,24 +1589,166 @@
 back );%0A%7D;%0A%0A
+/**%0A * Add an email account and connect it to its SMTP server%0A * @param %7BString%7D key  keyname%0A * @param %7BObject%7D data account credentials%0A */%0A
 mailer.addAc

add some docs to code