index.js
function init() {
	// Locate config if we dont have one {{{
	if (_.isUndefined(appConfig)) {
		appConfigLocations.forEach(function(key) {
			if (_.has(global, key)) {
				appConfig = _.get(global, key);
				return false;
			}
		});
		if (_.isUndefined(appConfig)) throw new Error('Cannot find email config in', appConfigLocations);
	}
	// }}}

	this.config = { // Reset basics
		from: appConfig.email.from,
		to: appConfig.email.to,
		subject: appConfig.email.subject || '',
		cc: appConfig.email.cc || [],
		bcc: appConfig.email.bcc || [],
	};

	// Work out mail transport {{{
	if (appConfig.email.enabled) {
		switch (appConfig.email.method) {
			case 'mailgun':
				if (
					/^https?:\/\//.test(appConfig.mailgun.domain) ||
					/mailgun/.test(appConfig.mailgun.domain)
				) throw new Error("Mailgun domain should not contain 'http(s)://' prefix or mailgun. Should resemble the domain name e.g. 'acme.com'");

				transporter = nodemailer.createTransport(nodemailerMailgun({
					auth: {
						api_key: appConfig.mailgun.apiKey,
						domain: appConfig.mailgun.domain,
					},
				}));
				break
			case 'sendmail':
				transporter = nodemailer.createTransport(nodemailerSendmail());
				break;
			default:
				next('Unknown mail transport method: ' + appConfig.email.method);
		}
	}
	// }}}

	return this;
}
function init() {
	// Locate config if we dont have one {{{
	if (_.isUndefined(appConfig)) {
		appConfigLocations.forEach(function(key) {
			if (_.has(global, key)) {
				appConfig = _.get(global, key);
				return false;
			}
		});
		if (_.isUndefined(appConfig)) throw new Error('Cannot find email config in', appConfigLocations);
	}
	// }}}

	this.config = { // Reset basics
		from: appConfig.email.from,
		to: appConfig.email.to,
		subject: appConfig.email.subject || '',
		cc: appConfig.email.cc || [],
		bcc: appConfig.email.bcc || [],
	};

	// Work out mail transport {{{
	if (appConfig.email.enabled) {
		switch (appConfig.email.method) {
			case 'mailgun':
				if (
					/^https?:\/\//.test(appConfig.mailgun.domain) ||
					/mailgun/.test(appConfig.mailgun.domain)
				) throw new Error("Mailgun domain should not contain 'http(s)://' prefix or mailgun. Should resemble the domain name e.g. 'acme.com'");

				transporter = nodemailer.createTransport(nodemailerMailgun({
					auth: {
						api_key: appConfig.mailgun.apiKey,
						domain: appConfig.mailgun.domain,
					},
				}));
				break
			case 'sendmail':
				transporter = nodemailer.createTransport(nodemailerSendmail());
				break;
			default:
				next('Unknown mail transport method: ' + appConfig.email.method);
		}
	}
	// }}}

	return this;
}
function init ( ) { // Locate config if we dont have one {{{ if ( _ . isUndefined ( appConfig ) ) { appConfigLocations . forEach ( function ( key ) { if ( _ . has ( global , key ) ) { appConfig = _ . get ( global , key ) ; return false ; } } ) ; if ( _ . isUndefined ( appConfig ) ) throw new Error ( 'Cannot find email config in' , appConfigLocations ) ; } // }}} this . config = { // Reset basics from : appConfig . email . from , to : appConfig . email . to , subject : appConfig . email . subject || '' , cc : appConfig . email . cc || [ ] , bcc : appConfig . email . bcc || [ ] , } ; // Work out mail transport {{{ if ( appConfig . email . enabled ) { switch ( appConfig . email . method ) { case 'mailgun' : if ( / ^https?:\/\/ / . test ( appConfig . mailgun . domain ) || / mailgun / . test ( appConfig . mailgun . domain ) ) throw new Error ( "Mailgun domain should not contain 'http(s)://' prefix or mailgun. Should resemble the domain name e.g. 'acme.com'" ) ; transporter = nodemailer . createTransport ( nodemailerMailgun ( { auth : { api_key : appConfig . mailgun . apiKey , domain : appConfig . mailgun . domain , } , } ) ) ; break case 'sendmail' : transporter = nodemailer . createTransport ( nodemailerSendmail ( ) ) ; break ; default : next ( 'Unknown mail transport method: ' + appConfig . email . method ) ; } } // }}} return this ; }
Array of places to look for config Is expected to contain at least a 'email' object and possibly 'mailgun' 
Initalize the emailer
If this is called multiple times it restarts the mail transport
@return {Object} This chainable object
Array of places to look for config Is expected to contain at least a email object and possibly mailgun Initalize the emailer If this is called multiple times it restarts the mail transport