Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Make mailer compatible with 10.4 - fixes #90 #141

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

/**
Expand Down
106 changes: 106 additions & 0 deletions Classes/Mail/MailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
declare(strict_types = 1);

/*
* This file is part of the package t3g/blog.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace T3G\AgencyPack\Blog\Mail;

use TYPO3\CMS\Core\Mail\MailMessage as CoreMailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class MailMessage
{
/**
* @var CoreMailMessage
*/
protected $mailMessage;

/**
* @var string
*/
protected $subject;

/**
* @var string
*/
protected $body;

/**
* @var array
*/
protected $from;

/**
* @var array
*/
protected $to;

public function __construct()
{
$this->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();
}
}
6 changes: 3 additions & 3 deletions Classes/Notification/CommentAddedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
]);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Notification/Processor/AdminNotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down