 
 	).then((html) ->
 		
-		if html?
-			
+		return unless html?
+		
+		html = if templateCache[type]?
+		
+			templateCache[type]
+			
+		else
+		
 			# Prepare the HTML to be sent as email.
-			html = sandbox.prepareHtmlForEmail html.toString()
-		
-			# Compile it with Handlebars.
-			mail.tokens ?= {}
-			html = handlebars.compile(html) mail.tokens
+			templateCache[type] = sandbox.prepareHtmlForEmail html.toString()
+	
+		# Compile it with Handlebars.
+		mail.tokens ?= {}
+		html = handlebars.compile(html) mail.tokens
 			
 	).then((html) ->
 		

						
						true
						
					# Rejoin the selectors, and cache the associated rules.
					selector = parts.join ','
					
					selectors[selector] ?= ''
					selectors[selector] += rule.style.cssText
			
			# CREDIT: http://devintorr.es/blog/2010/05/26/turn-css-rules-into-inline-style-attributes-using-jquery/
			# With some improvements, of course.
			sandbox.inlineCss = (html) ->
				for selector, cssText of selectors
					$(selector, $(html)).each (i, elm) ->
						elm.style.cssText += cssText
			
			# Prepare HTML for email; inject all CSS inline and insert niceties
			# like a nav on top.
			sandbox.prepareHtmlForEmail = (html) ->

readFile = Promise.promisify fs.readFile, fs

sandbox = null
templateCache = {}
transport = null

exports.$clearCaches = ->
	
	templateCache = {}
	
exports.$httpListening = (http) ->
	
	settings = nconf.get 'packageSettings:nodemailer'
