diff --git a/Classes/Messaging/MailMessage.php b/Classes/Mail/MailContent.php similarity index 97% rename from Classes/Messaging/MailMessage.php rename to Classes/Mail/MailContent.php index bfc88b15..a9238926 100644 --- a/Classes/Messaging/MailMessage.php +++ b/Classes/Mail/MailContent.php @@ -8,14 +8,14 @@ * LICENSE file that was distributed with this source code. */ -namespace T3G\AgencyPack\Blog\Messaging; +namespace T3G\AgencyPack\Blog\Mail; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Fluid\View\StandaloneView; -class MailMessage +class MailContent { /** diff --git a/Classes/Mail/MailMessage.php b/Classes/Mail/MailMessage.php new file mode 100644 index 00000000..b79651dd --- /dev/null +++ b/Classes/Mail/MailMessage.php @@ -0,0 +1,106 @@ +mailMessage = GeneralUtility::makeInstance(CoreMailMessage::class); + } + + public function setSubject(string $subject): self + { + $this->subject = $subject; + return $this; + } + + public function getSubject(): string + { + return $this->subject; + } + + public function setBody(string $body): self + { + $this->body = $body; + return $this; + } + + public function getBody(): string + { + return $this->body; + } + + public function setFrom(array $from): self + { + $this->from = $from; + return $this; + } + + public function getFrom(): array + { + return $this->from; + } + + public function setTo(array $to): self + { + $this->to = $to; + return $this; + } + + public function getTo(): array + { + return $this->to; + } + + public function send(): bool + { + $this->mailMessage->setSubject($this->getSubject()); + $this->mailMessage->setFrom($this->getFrom()); + $this->mailMessage->setTo($this->getTo()); + + if ($this->mailMessage instanceof \Symfony\Component\Mime\Email) { + $this->mailMessage->html($this->getBody()); + } else { + $this->mailMessage->setBody($this->getBody(), 'text/html'); + } + + return $this->mailMessage->send(); + } +} diff --git a/Classes/Notification/CommentAddedNotification.php b/Classes/Notification/CommentAddedNotification.php index c447de89..d0cba600 100644 --- a/Classes/Notification/CommentAddedNotification.php +++ b/Classes/Notification/CommentAddedNotification.php @@ -12,7 +12,7 @@ use T3G\AgencyPack\Blog\Domain\Model\Comment; use T3G\AgencyPack\Blog\Domain\Model\Post; -use T3G\AgencyPack\Blog\Messaging\MailMessage; +use T3G\AgencyPack\Blog\Mail\MailContent; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -42,8 +42,8 @@ public function getMessage(): string /** @var Post $post */ $post = $this->data['post']; - $mailMessage = GeneralUtility::makeInstance(MailMessage::class); - return $mailMessage->render('CommentAdded', [ + $mailContent = GeneralUtility::makeInstance(MailContent::class); + return $mailContent->render('CommentAdded', [ 'comment' => $comment, 'post' => $post ]); diff --git a/Classes/Notification/Processor/AdminNotificationProcessor.php b/Classes/Notification/Processor/AdminNotificationProcessor.php index 24029d5d..221ca190 100644 --- a/Classes/Notification/Processor/AdminNotificationProcessor.php +++ b/Classes/Notification/Processor/AdminNotificationProcessor.php @@ -10,9 +10,9 @@ namespace T3G\AgencyPack\Blog\Notification\Processor; +use T3G\AgencyPack\Blog\Mail\MailMessage; use T3G\AgencyPack\Blog\Notification\CommentAddedNotification; use T3G\AgencyPack\Blog\Notification\NotificationInterface; -use TYPO3\CMS\Core\Mail\MailMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; @@ -50,7 +50,7 @@ protected function processCommentAddNotification(NotificationInterface $notifica $mail = GeneralUtility::makeInstance(MailMessage::class); $mail ->setSubject($notification->getTitle()) - ->setBody($notification->getMessage(), 'text/html') + ->setBody($notification->getMessage()) ->setFrom([$settings['notifications']['email']['senderMail'] => $settings['notifications']['email']['senderName']]) ->setTo($emailAddresses) ->send(); diff --git a/Classes/Notification/Processor/AuthorNotificationProcessor.php b/Classes/Notification/Processor/AuthorNotificationProcessor.php index 204ed3bd..41d3744a 100644 --- a/Classes/Notification/Processor/AuthorNotificationProcessor.php +++ b/Classes/Notification/Processor/AuthorNotificationProcessor.php @@ -12,9 +12,9 @@ use T3G\AgencyPack\Blog\Domain\Model\Author; use T3G\AgencyPack\Blog\Domain\Model\Post; +use T3G\AgencyPack\Blog\Mail\MailMessage; use T3G\AgencyPack\Blog\Notification\CommentAddedNotification; use T3G\AgencyPack\Blog\Notification\NotificationInterface; -use TYPO3\CMS\Core\Mail\MailMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager;