Skip to content

Commit 59068b2

Browse files
committed
Add bounce email
1 parent 9284660 commit 59068b2

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

config/parameters.yml.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ parameters:
3232
app.password_reset_url: '%%env(PASSWORD_RESET_URL)%%'
3333
env(PASSWORD_RESET_URL): 'https://example.com/reset/'
3434

35+
# bounce email settings
36+
imap_bounce.email: '%%env(BOUNCE_EMAIL)%%'
37+
env(BOUNCE_EMAIL): '[email protected]'
38+
imap_bounce.password: '%%env(BOUNCE_IMAP_PASS)%%'
39+
env(BOUNCE_IMAP_PASS): '[email protected]'
40+
imap_bounce.host: '%%env(BOUNCE_IMAP_HOST)%%'
41+
env(BOUNCE_IMAP_HOST): 'imap.phplist.com'
42+
imap_bounce.port: '%%env(BOUNCE_IMAP_PORT)%%'
43+
env(BOUNCE_IMAP_PORT): 993
44+
imap_bounce.encryption: '%%env(BOUNCE_IMAP_ENCRYPTION)%%'
45+
env(BOUNCE_IMAP_ENCRYPTION): 'ssl'
46+
3547
# Messenger configuration for asynchronous processing
3648
app.messenger_transport_dsn: '%%env(MESSENGER_TRANSPORT_DSN)%%'
3749
env(MESSENGER_TRANSPORT_DSN): 'doctrine://default?auto_setup=true'

config/services/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
autoconfigure: true
1515
arguments:
1616
$defaultFromEmail: '%app.mailer_from%'
17+
$bounceEmail: '%imap_bounce.email%'
1718

1819
PhpList\Core\Domain\Subscription\Service\SubscriberDeletionService:
1920
autowire: true

src/Domain/Messaging/Service/EmailService.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@
66

77
use PhpList\Core\Domain\Messaging\Message\AsyncEmailMessage;
88
use Symfony\Component\Mailer\MailerInterface;
9+
use Symfony\Component\Mailer\Envelope;
910
use Symfony\Component\Messenger\MessageBusInterface;
1011
use Symfony\Component\Mime\Email;
1112
use Symfony\Component\Mime\Address;
1213

1314
class EmailService
1415
{
1516
private MailerInterface $mailer;
16-
private string $defaultFromEmail;
1717
private MessageBusInterface $messageBus;
18+
private string $defaultFromEmail;
19+
private string $bounceEmail;
1820

1921
public function __construct(
2022
MailerInterface $mailer,
23+
MessageBusInterface $messageBus,
2124
string $defaultFromEmail,
22-
MessageBusInterface $messageBus
25+
string $bounceEmail,
2326
) {
2427
$this->mailer = $mailer;
25-
$this->defaultFromEmail = $defaultFromEmail;
2628
$this->messageBus = $messageBus;
29+
$this->defaultFromEmail = $defaultFromEmail;
30+
$this->bounceEmail = $bounceEmail;
2731
}
2832

2933
public function sendEmail(
@@ -68,7 +72,12 @@ public function sendEmailSync(
6872
$email->attachFromPath($attachment);
6973
}
7074

71-
$this->mailer->send($email);
75+
$envelope = new Envelope(
76+
sender: new Address($this->bounceEmail, 'PHPList Bounce'),
77+
recipients: [new Address($email->getTo()[0]->getAddress())]
78+
);
79+
80+
$this->mailer->send(message: $email, envelope: $envelope);
7281
}
7382

7483
public function sendBulkEmail(

tests/Unit/Domain/Messaging/Service/EmailServiceTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ class EmailServiceTest extends TestCase
1919
private MailerInterface&MockObject $mailer;
2020
private MessageBusInterface&MockObject $messageBus;
2121
private string $defaultFromEmail = '[email protected]';
22+
private string $bounceEmail = '[email protected]';
2223

2324
protected function setUp(): void
2425
{
2526
$this->mailer = $this->createMock(MailerInterface::class);
2627
$this->messageBus = $this->createMock(MessageBusInterface::class);
27-
$this->emailService = new EmailService($this->mailer, $this->defaultFromEmail, $this->messageBus);
28+
$this->emailService = new EmailService(
29+
mailer: $this->mailer,
30+
messageBus: $this->messageBus,
31+
defaultFromEmail: $this->defaultFromEmail,
32+
bounceEmail: $this->bounceEmail,
33+
);
2834
}
2935

3036
public function testSendEmailWithDefaultFrom(): void

0 commit comments

Comments
 (0)