diff --git a/site/app/Resources/views/template/email_template.html.twig b/site/app/Resources/views/template/email_template.html.twig
new file mode 100644
index 00000000..1560bc69
--- /dev/null
+++ b/site/app/Resources/views/template/email_template.html.twig
@@ -0,0 +1,249 @@
+
+
+
+
+ New Notification from LibreCores
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hi {{ username }}, |
+
+
+ You have a new Notification from LibreCores. |
+
+
+
+ {{ content }}
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {# TODO:Update the link after merge of notification settings page #}
+
+ You are recieving this notification because you are subscribed to email notifications from LibreCores by default.
+ You can snooze these notifications if you want to. For detailed preferences,
+ go to notification settings of your LibreCores account.
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
diff --git a/site/app/config/packages/swiftmailer.yml b/site/app/config/packages/swiftmailer.yml
index d3ecd138..a8acde3f 100644
--- a/site/app/config/packages/swiftmailer.yml
+++ b/site/app/config/packages/swiftmailer.yml
@@ -5,4 +5,3 @@ swiftmailer:
port: "%mailer_port%"
username: "%mailer_user%"
password: "%mailer_password%"
- spool: { type: memory }
diff --git a/site/src/Consumer/EmailNotificationConsumer.php b/site/src/Consumer/EmailNotificationConsumer.php
index 36da2249..91ee7397 100644
--- a/site/src/Consumer/EmailNotificationConsumer.php
+++ b/site/src/Consumer/EmailNotificationConsumer.php
@@ -2,9 +2,10 @@
namespace App\Consumer;
-use App\Util\Notification;
+use FOS\UserBundle\Model\UserManagerInterface;
use Psr\Log\LoggerInterface;
-
+use Twig\Environment;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Sends out Notifications over email
*
@@ -12,26 +13,93 @@
*/
class EmailNotificationConsumer extends AbstractNotificationConsumer
{
+ /**
+ * @var UserManagerInterface
+ */
+ protected $userManager;
+
+ /**
+ * @var \Swift_Mailer
+ */
+ protected $mailer;
+
+ /**
+ * @var Environment
+ */
+ protected $twig;
+
+ /**
+ * @var ContainerInterface
+ */
+ protected $container;
+
/**
* EmailNotificationConsumer constructor
*
- * @param LoggerInterface $logger
+ * @param LoggerInterface $logger
+ * @param UserManagerInterface $userManager
+ * @param Environment $twig
+ * @param \Swift_Mailer $mailer
*/
- public function __construct(LoggerInterface $logger)
+ public function __construct(
+ LoggerInterface $logger,
+ UserManagerInterface $userManager,
+ Environment $twig,
+ \Swift_Mailer $mailer,
+ ContainerInterface $container
+ )
{
parent::__construct($logger);
+ $this->userManager = $userManager;
+ $this->twig = $twig;
+ $this->mailer = $mailer;
+ $this->container = $container;
+ }
+
+ protected function shouldHandle()
+ {
+ $type = $this->notification->getType();
+ // TODO: Check subscription status also from database, after merge of #387
+ switch ($type) {
+ case "site_information":
+ $this->logger->info('Processing the notification and sending an email...');
+
+ return true;
+ default:
+ $this->logger->error('Something went wrong. Please check the notification type');
+
+ return false;
+ }
}
/**
* Handles an email Notification
*
* @return bool
+ *
+ * @throws \Exception
*/
protected function handle(): bool
{
- // TODO: Process the Notification($this->notification)
echo "Email Notification Consumer";
+ $userEmail = $this->userManager->findUserByUsername($this->notification->getRecipient()->getUsername());
+
+ $mailer = $this->container->getParameter('mailer_user');
+
+ $message = (new \Swift_Message($this->notification->getSubject()))
+ // Set sender's email from a yaml file
+ ->setFrom($mailer)
+ ->setTo($userEmail)
+ ->setBody($this->twig->render('template/email_template.html.twig', [
+ 'username' => $this->notification->getRecipient()->getUsername(),
+ 'content' => $this->notification->getMessage(),
+ ]), 'text/html')
+ // Alternate body for users who have text/plain preferences
+ ->addPart($this->notification->getMessage(), 'text/plain');
+
+ $this->mailer->send($message);
+
return true;
}
}