diff --git a/Classes/Utility/MailUtility.php b/Classes/Utility/MailUtility.php
new file mode 100644
index 0000000..e666996
--- /dev/null
+++ b/Classes/Utility/MailUtility.php
@@ -0,0 +1,207 @@
+
+ *
+ ***/
+
+use TYPO3\CMS\Core\Mail\MailMessage;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Extbase\Service\ImageService;
+use TYPO3\CMS\Fluid\View\StandaloneView;
+use TYPO3\CMS\Fluid\View\TemplatePaths;
+
+/**
+ *
+ */
+class MailUtility
+{
+ /**
+ * tages maildata, builds html and text mails an decides where to send them
+ * allows to intercept sender for testing
+ *
+ * @param string $target email or group identifier
+ * @param string $subject mail subject, prefixed by setting in ts
+ * @param array $data content for email, gets parsed in different ways
+ * @return void
+ */
+ public static function sendMail(
+ $target,
+ $sender,
+ $subject,
+ $data,
+ $templateRootPaths = null,
+ $templateNameHtml = null,
+ $templateNameText = null
+ ) {
+ if (!$templateRootPaths) {
+ $templatePaths = new TemplatePaths();
+ $templatePaths->fillDefaultsByPackageName('templates_aide');
+ $templateRootPaths = $templatePaths->getTemplateRootPaths();
+ }
+ if (!$templateNameHtml) {
+ $templateNameHtml = 'Mailing/DefaultHtml';
+ }
+ if (!$templateNameText) {
+ $templateNameText = 'Mailing/DefaultText';
+ }
+ $htmlView = GeneralUtility::makeInstance(StandaloneView::class);
+ $htmlView->setTemplateRootPaths($templateRootPaths);
+ $htmlView->setTemplate($templateNameHtml);
+ $textView = GeneralUtility::makeInstance(StandaloneView::class);
+ $textView->setTemplateRootPaths($templateRootPaths);
+ $textView->setTemplate($templateNameText);
+ $mail = GeneralUtility::makeInstance(MailMessage::class);
+ $mail->setFrom($sender);
+ $mail->setSubject($subject);
+ $bodydataText = [];
+ $bodydataHtml = [];
+ foreach ($data as $row) {
+ switch($row['type']) {
+ case 'text':
+ case 'headline':
+ $htmlRow = $row;
+ $htmlRow['data'] = preg_replace_callback(
+ '/\[.*\]/mU',
+ function($matches) {
+
+ foreach ($matches as $match) {
+ return preg_replace_callback(
+ '/\[(\S*)\s(.*)\]/mU',
+ function($matchesInner) {
+ return ''
+ . $matchesInner[2]
+ . '';
+ },
+ $match
+ );
+ }
+ },
+ $htmlRow['data']
+ );
+ $textRow = $row;
+ $textRow['data'] = preg_replace_callback(
+ '/\[.*\]/mU',
+ function($matches) {
+ foreach ($matches as $match) {
+ return preg_replace_callback(
+ '/\[(\S*)\s(.*)\]/mU',
+ function($matchesInner) {
+ return $matchesInner[2]
+ . ': '
+ . $matchesInner[1];
+ },
+ $match
+ );
+ }
+ },
+ $textRow['data']
+ );
+ $bodydataText[] = $textRow;
+ $bodydataHtml[] = $htmlRow;
+ break;
+ case 'button':
+ case 'buttons':
+ $htmlRow = $row;
+ //$htmlRow['targets'] = preg_replace_callback(
+ // '/\[.*\]/mU',
+ // function($matches) {
+ // foreach ($matches as $match) {
+ // return preg_replace_callback(
+ // '/\[(\S*)\s(.*)\]/mU',
+ // function($matchesInner) {
+ // return $matchesInner;
+ // //return ''
+ // // . $matchesInner[2]
+ // // . '';
+ // },
+ // $match
+ // );
+ // }
+ // },
+ // $htmlRow['targets']
+ //);
+ $textRow = $row;
+ //$textRow['targets'] = preg_replace_callback(
+ // '/\[.*\]/mU',
+ // function($matches) {
+ // foreach ($matches as $match) {
+ // return preg_replace_callback(
+ // '/\[(\S*)\s(.*)\]/mU',
+ // function($matchesInner) {
+ // return $matchesInner;
+ // //return $matchesInner[2]
+ // // . ': '
+ // // . $matchesInner[1];
+ // },
+ // $match
+ // );
+ // }
+ // },
+ // $textRow['targets']
+ //);
+ $bodydataText[] = $textRow;
+ $bodydataHtml[] = $htmlRow;
+ break;
+ case 'attachmentBase64':
+ $attachmentdata = explode(',', $row['data']);
+ preg_match('/\w*:(.*);\w*/', $attachmentdata[0], $matches);
+ $mimetype = $matches[1];
+ preg_match('/\w*\/(.*);\w*/', $attachmentdata[0], $matches);
+ $fileextension = $matches[1];
+ $mail->attach(new \Swift_Attachment(
+ base64_decode($attachmentdata[1]),
+ 'attachment.' . $fileextension,
+ $mimetype
+ ));
+ break;
+ }
+ }
+ $textView->assign('content', $bodydataText);
+ $htmlView->assign('content', $bodydataHtml);
+ $domain = GeneralUtility::locationHeaderUrl('/');
+ $htmlView->assign('domain', $domain);
+ $textBody = $textView->render();
+ $htmlBody = $htmlView->render();
+ $mail->setBody($textBody);
+ $mail->addPart($htmlBody, 'text/html');
+ $recipients = explode(
+ ',',
+ $target
+ );
+ if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['intercept_to']) {
+ $subjectOrig = $mail->getSubject();
+ $recipientsIntercecpted = explode(
+ ',',
+ $GLOBALS['TYPO3_CONF_VARS']['MAIL']['intercept_to']
+ );
+ foreach ($recipientsIntercecpted as $recipientIntercepted) {
+ foreach ($recipients as $recipient) {
+ $mail->setSubject(
+ $subjectOrig . ' [ORIG-TO: ' . trim($recipient) . ']'
+ );
+ $mail->setTo(trim($recipientIntercepted));
+ $mail->send();
+ }
+ }
+ } else {
+ foreach ($recipients as $recipient) {
+ $mail->setTo(trim($recipient));
+ $mail->send();
+ }
+ }
+ }
+}
diff --git a/Resources/Private/Templates/Mailing/DefaultHtml.html b/Resources/Private/Templates/Mailing/DefaultHtml.html
new file mode 100644
index 0000000..ca7e1a9
--- /dev/null
+++ b/Resources/Private/Templates/Mailing/DefaultHtml.html
@@ -0,0 +1,394 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {row.data.0 -> f:format.nl2br() -> f:format.raw()}
+
+ |
+
+
+
+
+
+
+
+
+
+ {row.data.1 -> f:format.nl2br() -> f:format.raw()}
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {row.data -> f:format.nl2br() -> f:format.raw()}
+
+
+ {row.data -> f:format.nl2br() -> f:format.raw()}
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Resources/Private/Templates/Mailing/DefaultText.html b/Resources/Private/Templates/Mailing/DefaultText.html
new file mode 100644
index 0000000..f923ea4
--- /dev/null
+++ b/Resources/Private/Templates/Mailing/DefaultText.html
@@ -0,0 +1,20 @@
+
+
+
+
+ {row.data.0}: {row.data.1}
+
+ = {row.data} =
+ {row.data}
+
+
+{br}{br}
+ {br}{br}{row.targets.0.1}:{br}{row.targets.0.0}{br}{br}{row.targets.1.1}:{br}{row.targets.1.0}
+
+ {br}{br}{row.targets.0.1}:{br}{row.targets.0.0}
+