Skip to content

Commit cdc7b8c

Browse files
committed
Add transport option for mailer transport dsn
1 parent c3558ff commit cdc7b8c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Classes/Channel/EmailChannel.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
1616
use Swisscom\CommunicationDispatcher\Exception;
1717
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
18+
use Symfony\Component\Mailer\Transport;
1819
use Symfony\Component\Mime\Address;
1920
use Symfony\Component\Mime\Email;
2021

@@ -35,6 +36,11 @@ class EmailChannel implements ChannelInterface
3536
*/
3637
protected $resourceManager;
3738

39+
/**
40+
* @var string|null
41+
*/
42+
protected $transport;
43+
3844
/**
3945
* @var array<string, string>
4046
*/
@@ -55,6 +61,7 @@ class EmailChannel implements ChannelInterface
5561
*/
5662
function __construct(array $options = [])
5763
{
64+
$this->transport = $options['transport'] ?? null;
5865
$this->from = $options['from'] ?? '';
5966
$this->replyTo = $options['replyTo'] ?? '';
6067
$this->cc = $options['cc'] ?? '';
@@ -113,7 +120,12 @@ public function send(Recipient $recipient, string $subject, string $text, array
113120
}
114121
}
115122

116-
$mailer = $this->mailerService->getMailer();
123+
$transport = null;
124+
if ($this->transport !== null) {
125+
$transport = Transport::fromDsn($this->transport);
126+
}
127+
128+
$mailer = $this->mailerService->getMailer($transport);
117129
$mailer->send($email);
118130
}
119131

0 commit comments

Comments
 (0)