public function fetchTemplate($template,$data = array(),$outtemplate = null) {
		// template is required
		if (trim($template) == '') {
			throw new \Exception('No template to format email');
		}
		
		$templatedata = $this->getTemplateData($template);
		
		// use default out template if is not provided
		if ($outtemplate === null) {
			$outtemplate = 'default';
		}
		
		// template is not found in any locale
		if (!is_array($templatedata)) {
			throw new \Exception(sprintf('Email template %s not found',$template));
		}
		
		// if email template provided.
		if ($outtemplate != '') {
			$outtemplate_real = $this->getOutTemplate($outtemplate);
			
			if (!$outtemplate_real) {
				throw new \Exception(sprintf('Email template %s not found',$outtemplate));
			}
			
			$outtemplate = $outtemplate_real;
		}
		
		// create template processor object
		$class = $this->templateprocessorclass;
		$templating = new $class();
		
		// init template processor
		$templating->init($this->tepmlateprocessorinitoptions);

		if (is_object($this->options['application'])) {
			$templating->setApplication($this->options['application']);
		}
		
		// check if template processor can access a template
		if (!$templating->checkTemplateExists($templatedata['file'])) {
			throw new \Exception(sprintf('Email template %s not found',$template));
		}
		
		// set data to fetch with the template
		$templating->setVars($data);
		
		// fetch subject template (it also can contains some wildcards)
		$subject = $templating->fetchString($templatedata['subject']);
		
		$templating->setTemplate($templatedata['file']);
		
		// generate email body
		$emailhtml = $templating->fetchTemplate();
		
		// insert a body to a common outer template
		if ($outtemplate != '') {
			$templating->setVar('EMAILCONTENT',$emailhtml);
			
			$templating->setTemplate($outtemplate);
			
			$emailhtml = $templating->fetchTemplate();
		}
		
		// return body and subject
		return array('body'=>$emailhtml,'subject'=>$subject);
	}