Skip to content

Commit

Permalink
chore: replace swiftmailer with symfony/mailer (#391)
Browse files Browse the repository at this point in the history
* feat: replace swift_mailer with symfony/mailer

* fix passwordreset-test

* fix typo

* remove swiftmailer-bundle

* fix tests

* fiix test
  • Loading branch information
Lundli authored Nov 2, 2023
1 parent 4329436 commit 10c5865
Show file tree
Hide file tree
Showing 23 changed files with 307 additions and 466 deletions.
10 changes: 1 addition & 9 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ APP_SECRET=18f75b05e6fb58bd7d83b1932a0df935
REMEMBER_ME_NAME=VPREMEMBER

###> symfony/mailer ###
# MAILER_DSN=null://null
MAILER_DSN=null://null
###< symfony/mailer ###

###> doctrine/doctrine-bundle ###
Expand All @@ -39,14 +39,6 @@ GOOGLE_CLIENT_ID="xxxxx"
GOOGLE_CLIENT_SECRET="xxxxx"
GOOGLE_API_REFRESH_TOKEN="xxxxx"
###< google/apiclient ###

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

# GeoLocation
IPINFO_TOKEN=""
GEO_IGNORED_ASNS=[]
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"symfony/serializer": "5.4.*",
"symfony/slack-notifier": "5.4.*",
"symfony/string": "5.4.*",
"symfony/swiftmailer-bundle": "^3.5",
"symfony/twig-bundle": "^5.4",
"symfony/validator": "5.4.*",
"symfony/web-link": "5.4.*",
Expand Down
159 changes: 1 addition & 158 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle::class => ['all' => true],
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
Expand Down
4 changes: 0 additions & 4 deletions config/packages/dev/swiftmailer.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions config/packages/swiftmailer.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions config/packages/test/swiftmailer.yaml

This file was deleted.

30 changes: 14 additions & 16 deletions src/EventSubscriber/ApplicationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Mailer\MailingInterface;
use App\Service\AdmissionNotifier;
use App\Service\UserRegistration;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;

Expand Down Expand Up @@ -34,7 +35,7 @@ public static function getSubscribedEvents(): array
];
}

public function createAdmissionSubscriber(ApplicationCreatedEvent $event)
public function createAdmissionSubscriber(ApplicationCreatedEvent $event): void
{
$application = $event->getApplication();
$department = $application->getUser()->getDepartment();
Expand All @@ -46,7 +47,7 @@ public function createAdmissionSubscriber(ApplicationCreatedEvent $event)
}
}

public function sendConfirmationMail(ApplicationCreatedEvent $event)
public function sendConfirmationMail(ApplicationCreatedEvent $event): void
{
$application = $event->getApplication();
$user = $application->getUser();
Expand All @@ -61,20 +62,17 @@ public function sendConfirmationMail(ApplicationCreatedEvent $event)
}

// Send a confirmation email with a copy of the application
$emailMessage = (new \Swift_Message())
->setSubject('Søknad - Vektorassistent')
->setReplyTo($application->getDepartment()->getEmail())
->setTo($application->getUser()->getEmail())
->setBody(
$this->twig->render(
$template,
[
'application' => $application,
'newUserCode' => $newUserCode,
]
),
'text/html'
);
$emailMessage = (new TemplatedEmail())
->subject('Søknad - Vektorassistent')
->replyTo($application->getDepartment()->getEmail())
->to($application->getUser()->getEmail())
->from('[email protected]')
->htmlTemplate($template)
->context([
'application' => $application,
'newUserCode' => $newUserCode,
]);

$this->mailer->send($emailMessage);
}
}
47 changes: 25 additions & 22 deletions src/EventSubscriber/InterviewSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use App\Sms\Sms;
use App\Sms\SmsSenderInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Mime\Address;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

Expand Down Expand Up @@ -55,26 +57,26 @@ public static function getSubscribedEvents(): array
];
}

public function sendInterviewReceipt(InterviewConductedEvent $event)
public function sendInterviewReceipt(InterviewConductedEvent $event): void
{
$application = $event->getApplication();
$interviewer = $application->getInterview()->getInterviewer();

// Send email to the interviewee with a summary of the interview
$emailMessage = (new \Swift_Message())
->setSubject('Vektorprogrammet intervju')
->setReplyTo([$interviewer->getDepartment()->getEmail() => 'Vektorprogrammet'])
->setTo($application->getUser()->getEmail())
->setReplyTo($interviewer->getEmail())
->setBody($this->twig->render('interview/interview_summary_email.html.twig', [
$emailMessage = (new TemplatedEmail())
->subject('Vektorprogrammet intervju')
->replyTo(new Address($interviewer->getDepartment()->getEmail(), 'Vektorprogrammet'))
->to($application->getUser()->getEmail())
->from(new Address('[email protected]', 'Vektorprogrammet.no'))
->htmlTemplate('interview/interview_summary_email.html.twig')
->context([
'application' => $application,
'interviewer' => $interviewer,
]))
->setContentType('text/html');
]);
$this->mailer->send($emailMessage);
}

public function addFlashMessage(InterviewConductedEvent $event)
public function addFlashMessage(InterviewConductedEvent $event): void
{
$user = $event->getApplication()->getUser();
$message = "Intervjuet med $user ble lagret. En kvittering med et sammendrag av
Expand All @@ -83,7 +85,7 @@ public function addFlashMessage(InterviewConductedEvent $event)
$this->requestStack->getSession()->getFlashBag()->add('success', $message);
}

public function logEvent(InterviewConductedEvent $event)
public function logEvent(InterviewConductedEvent $event): void
{
$application = $event->getApplication();

Expand All @@ -94,7 +96,7 @@ public function logEvent(InterviewConductedEvent $event)
$this->logger->info("$department: New interview with $interviewee registered");
}

public function sendSlackNotifications(InterviewConductedEvent $event)
public function sendSlackNotifications(InterviewConductedEvent $event): void
{
$application = $event->getApplication();

Expand All @@ -116,12 +118,12 @@ public function sendSlackNotifications(InterviewConductedEvent $event)
}
}

public function sendScheduleEmail(InterviewEvent $event)
public function sendScheduleEmail(InterviewEvent $event): void
{
$this->interviewManager->sendScheduleEmail($event->getInterview(), $event->getData());
}

public function sendScheduleSms(InterviewEvent $event)
public function sendScheduleSms(InterviewEvent $event): void
{
$interview = $event->getInterview();
$data = $event->getData();
Expand Down Expand Up @@ -166,17 +168,18 @@ public function sendScheduleSms(InterviewEvent $event)
$this->smsSender->send($sms);
}

public function sendCoAssignedEmail(InterviewEvent $event)
public function sendCoAssignedEmail(InterviewEvent $event): void
{
$interview = $event->getInterview();
$emailMessage = (new \Swift_Message())
->setSubject('Vektorprogrammet intervju')
->setFrom(['[email protected]' => 'Vektorprogrammet'])
->setTo($interview->getInterviewer()->getEmail())
->setReplyTo($interview->getCoInterviewer()->getEmail())
->setBody($this->twig->render('interview/co_interviewer_email.html.twig', [
$emailMessage = (new TemplatedEmail())
->subject('Vektorprogrammet intervju')
->from(new Address('[email protected]', 'Vektorprogrammet'))
->to($interview->getInterviewer()->getEmail())
->replyTo($interview->getCoInterviewer()->getEmail())
->htmlTemplate('interview/co_interviewer_email.html.twig')
->context([
'interview' => $interview,
]));
]);
$this->mailer->send($emailMessage);
}
}
Loading

0 comments on commit 10c5865

Please sign in to comment.