Skip to content

Commit 74541cd

Browse files
Merge pull request #8493 from carlobeltrame/reply-to-on-camp-invitation
Set reply-to on camp invitation mails
2 parents f1b7b22 + 9b3c345 commit 74541cd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

api/src/Service/MailService.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Profile;
88
use App\Entity\User;
99
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
10+
use Symfony\Bundle\SecurityBundle\Security;
1011
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
1112
use Symfony\Component\Mailer\MailerInterface;
1213
use Symfony\Component\Mime\Address;
@@ -22,13 +23,19 @@ public function __construct(
2223
private readonly Environment $twigEnironment,
2324
private readonly string $frontendBaseUrl,
2425
private readonly string $senderEmail,
25-
private readonly string $senderName = ''
26+
private readonly string $senderName,
27+
private readonly Security $security,
2628
) {}
2729

2830
public function sendInviteToCampMail(User $byUser, Camp $camp, string $key, string $emailToInvite): void {
31+
/** @var User $originator */
32+
$originator = $this->security->getUser();
33+
$originatorEmail = $originator->getEmail();
34+
$originatorName = $originator->getDisplayName();
2935
$email = new TemplatedEmail()
3036
->from(new Address($this->senderEmail, $this->senderName))
3137
->to(new Address($emailToInvite))
38+
->replyTo(new Address($originatorEmail, $originatorName))
3239
->subject($this->translator->trans('inviteToCamp.subject', ['campTitle' => $camp->title], self::TRANSLATE_DOMAIN, $byUser->profile->language))
3340
->htmlTemplate($this->getTemplate('emails/campCollaborationInvite.{language}.html.twig', $byUser))
3441
->textTemplate($this->getTemplate('emails/campCollaborationInvite.{language}.text.twig', $byUser))

api/tests/Service/MailServiceTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Service\MailService;
1111
use PHPUnit\Framework\Attributes\DataProvider;
1212
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
13+
use Symfony\Bundle\SecurityBundle\Security;
1314
use Symfony\Component\Mailer\MailerInterface;
1415
use Symfony\Contracts\Translation\TranslatorInterface;
1516
use Twig\Environment;
@@ -23,6 +24,7 @@ class MailServiceTest extends KernelTestCase {
2324

2425
private Camp $camp;
2526
private User $user;
27+
private Security $security;
2628

2729
private MailService $mailer;
2830

@@ -33,7 +35,15 @@ protected function setUp(): void {
3335
$translator = self::getContainer()->get(TranslatorInterface::class);
3436
$twigEnvironment = self::getContainer()->get(Environment::class);
3537

36-
$this->mailer = new MailService($mailer, $translator, $twigEnvironment, 'frontend.example.com', '[email protected]', 'SenderName');
38+
$this->security = $this->createMock(Security::class);
39+
$profile = new Profile();
40+
$profile->nickname = 'Linux';
41+
$profile->email = '[email protected]';
42+
$user = new User();
43+
$user->profile = $profile;
44+
$this->security->method('getUser')->willReturn($user);
45+
46+
$this->mailer = new MailService($mailer, $translator, $twigEnvironment, 'frontend.example.com', '[email protected]', 'SenderName', $this->security);
3747

3848
$this->user = new User();
3949
$profile = new Profile();
@@ -52,6 +62,7 @@ public function testSendInviteToCampMailDeChScout() {
5262
self::assertEmailCount(1);
5363
$mailerMessage = self::getMailerMessage(0);
5464
self::assertEmailAddressContains($mailerMessage, 'To', self::INVITE_MAIL);
65+
self::assertEmailAddressContains($mailerMessage, 'reply-to', '[email protected]');
5566
self::assertEmailHeaderSame($mailerMessage, 'subject', '[eCamp v3] Du wurdest ins Lager "some camp title" eingeladen');
5667

5768
self::assertEmailHtmlBodyContains($mailerMessage, $this->camp->title);
@@ -71,6 +82,7 @@ public function testSendInvitationMailDoesNotCrashForAllLanguages(string $langua
7182
self::assertEmailCount(1);
7283
$mailerMessage = self::getMailerMessage(0);
7384
self::assertEmailAddressContains($mailerMessage, 'To', self::INVITE_MAIL);
85+
self::assertEmailAddressContains($mailerMessage, 'reply-to', '[email protected]');
7486

7587
self::assertEmailHtmlBodyContains($mailerMessage, $this->camp->title);
7688
self::assertEmailHtmlBodyContains($mailerMessage, $this->user->getDisplayName());

0 commit comments

Comments
 (0)