feat: send mailings over MailJet smtp in dedicated worker process

This commit is contained in:
Björn Fromme
2026-08-12 15:47:04 +02:00
parent a5c98025d0
commit e0a9562fc6
14 changed files with 480 additions and 44 deletions
@@ -5,6 +5,7 @@ namespace App\Controller\Admin\Teamer;
use App\Controller\Traits\ReturnUrlTrait;
use App\Form\TeamerMailingType;
use App\Htmx\HxRedirectResponse;
use App\Message\SendTeamerMailing;
use App\Service\Common\TeamerFilterHandler;
use App\Service\Teamer\TeamerMailingDraftHandler;
use App\Service\Teamer\TeamerMailingService;
@@ -12,6 +13,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
@@ -23,6 +25,7 @@ class MailingController extends AbstractController
private readonly TeamerFilterHandler $filterHandler,
private readonly TeamerMailingService $mailingService,
private readonly TeamerMailingDraftHandler $draftHandler,
private readonly MessageBusInterface $messageBus,
) {
}
@@ -114,12 +117,25 @@ class MailingController extends AbstractController
}
$recipients = $this->mailingService->resolveRecipients($this->filterHandler->getFilterSettings());
$count = $this->mailingService->send($form->getData(), $recipients);
$mailingDto = $form->getData();
// it went out, the next mailing starts on a blank page
// the recipients travel with the message, so the mailing reaches exactly the
// people the confirmation modal counted even though it is sent from a worker
$this->messageBus->dispatch(SendTeamerMailing::fromRecipients(
(string) $mailingDto->getSubject(),
(string) $mailingDto->getMessage(),
$recipients
));
// it is on its way, the next mailing starts on a blank page
$this->draftHandler->resetDraft();
$this->addFlash('success', sprintf('Die Mail wurde an %d Teamer:innen gesendet', $count));
// deliberately not "wurde gesendet": at this point nothing has been handed to a
// mail server yet, and saying otherwise would make a failed mailing look fine
$this->addFlash('success', sprintf(
'Die Mail wird an %d Teamer:innen gesendet',
$recipients->getEligibleCount()
));
return new HxRedirectResponse($this->generateUrl('app_administrative_teamer_index'));
}