From 6b05d1443acdf87d975a94a36ca102239cdf7b1f Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Wed, 28 Sep 2016 22:21:54 +0200
Subject: [PATCH] [TASK] Using Default BCC and CC from config

---
 Classes/Service/MailTemplateService.php | 16 ++++++++++++----
 Configuration/TypoScript/setup.ts       |  4 ++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php
index 032d867e..c6cb2e9e 100644
--- a/Classes/Service/MailTemplateService.php
+++ b/Classes/Service/MailTemplateService.php
@@ -120,6 +120,14 @@ class MailTemplateService {
 		$typoScriptSettingsService = $objectManager->get(TypoScriptSettingsService::class);
 		$this->tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
 		$this->language = $this->tsSettings['templateDefaultLanguage'];
+
+		$this->fromAddress = $this->tsSettings['mail']['default']['from'];
+		$this->mailMessage->setFrom($this->fromAddress);
+
+		$this->bccAddresses = explode(',', $this->tsSettings['mail']['default']['bcc']);
+		$this->ccAddresses = explode(',', $this->tsSettings['mail']['default']['cc']);
+		$this->mailMessage->setBcc($this->bccAddresses);
+		$this->mailMessage->setBcc($this->ccAddresses);
 	}
 
 	/**
@@ -239,8 +247,8 @@ class MailTemplateService {
 	 * @return MailTemplateService
 	 */
 	public function setCcAddresses($ccAddresses) {
-		$this->ccAddresses = $ccAddresses;
-		$this->mailMessage->setCc($ccAddresses);
+		$this->ccAddresses[] = $ccAddresses;
+		$this->mailMessage->setCc($this->ccAddresses);
 		return $this;
 	}
 
@@ -314,8 +322,8 @@ class MailTemplateService {
 	 * @return MailTemplateService
 	 */
 	public function setBccAddresses(array $bccAddresses) {
-		$this->bccAddresses = $bccAddresses;
-		$this->mailMessage->setBcc($bccAddresses);
+		$this->bccAddresses[] = $bccAddresses;
+		$this->mailMessage->setBcc($this->bccAddresses);
 		return $this;
 	}
 
diff --git a/Configuration/TypoScript/setup.ts b/Configuration/TypoScript/setup.ts
index 8ba752f8..f05b9320 100644
--- a/Configuration/TypoScript/setup.ts
+++ b/Configuration/TypoScript/setup.ts
@@ -9,6 +9,10 @@ module.tx_sgmail {
 		mail {
 			test.from = info@test.de
 			test.subject = This is just a Test E-Mail
+
+			default.from = noreply@ele.de
+			default.bcc = torsten@sgalinski.de, stefan@sgalinski.de
+			default.cc = torsten@sgalinski.de
 		}
 
 		templateDefaultLanguage = en
-- 
GitLab