From d09e6a975c4246a6f9b82d8fadcd9a251e7f7ba4 Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Tue, 4 Oct 2016 15:41:11 +0200
Subject: [PATCH] [TASK] Fixing Preview Mail, now shows markes

---
 Classes/Controller/MailController.php    |  2 +-
 Classes/Service/MailTemplateService.php  | 24 +++++++++++++++++++-----
 Resources/Private/Language/locallang.xlf |  4 ++--
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/Classes/Controller/MailController.php b/Classes/Controller/MailController.php
index 23aa0e07..fc2ab82f 100644
--- a/Classes/Controller/MailController.php
+++ b/Classes/Controller/MailController.php
@@ -283,7 +283,7 @@ class MailController extends ActionController {
 		$mailTemplateService->setTemplateName($selectedTemplateKey);
 		$mailTemplateService->setExtensionKey($selectedExtensionKey);
 
-		if ($mailTemplateService->sendEmail()) {
+		if ($mailTemplateService->sendEmail(true)) {
 			$message = LocalizationUtility::translate('backend.success_mail', 'sg_mail');
 			$this->addFlashMessage($message, '', FlashMessage::OK);
 		} else {
diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php
index 71228618..741b4ac7 100644
--- a/Classes/Service/MailTemplateService.php
+++ b/Classes/Service/MailTemplateService.php
@@ -193,13 +193,10 @@ class MailTemplateService {
 	/**
 	 * Send the Email
 	 *
+	 * @param boolean $isPreview
 	 * @return boolean email was sent or added to mail queue successfully?
 	 */
-	public function sendEmail() {
-
-		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-		/** @var StandaloneView $emailView */
-		$emailView = $objectManager->get(StandaloneView::class);
+	public function sendEmail($isPreview = FALSE) {
 
 		/** @var Template $template */
 		$template = $this->templateRepository->findTemplate(
@@ -219,6 +216,23 @@ class MailTemplateService {
 			}
 		}
 
+		if ($isPreview) {
+			if (!isset($defaultTemplateContent)) {
+				$this->mailMessage->setBody($template->getContent());
+				$this->mailMessage->setSubject($template->getSubject());
+			} else {
+				$this->mailMessage->setBody($defaultTemplateContent);
+				$this->mailMessage->setSubject('');
+			}
+
+			$this->mailMessage->send();
+			return TRUE;
+		}
+
+		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+		/** @var StandaloneView $emailView */
+		$emailView = $objectManager->get(StandaloneView::class);
+
 		if (!isset($defaultTemplateContent)) {
 			$emailView->setTemplateSource($template->getContent());
 			$this->mailMessage->setSubject($template->getSubject());
diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf
index 661f4e7b..20f05a3c 100644
--- a/Resources/Private/Language/locallang.xlf
+++ b/Resources/Private/Language/locallang.xlf
@@ -34,7 +34,7 @@
 			<source>Language (Reloads the page):</source>
 		</trans-unit>
 		<trans-unit id="backend.send_test">
-			<source>Send Test Email</source>
+			<source>Send Preview Mail</source>
 		</trans-unit>
 		<trans-unit id="backend.subject">
 			<source>Subject:</source>
@@ -65,4 +65,4 @@
 		</trans-unit>
 		</body>
 	</file>
-</xliff>
\ No newline at end of file
+</xliff>
-- 
GitLab