Skip to content

Commit d413ef9

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [Mailer] Add custom transport factories
2 parents 9646ce1 + 3eb4655 commit d413ef9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

mailer.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,35 @@ Other Options
421421

422422
The ``max_per_second`` option was introduced in Symfony 6.2.
423423

424+
Custom Transport Factories
425+
~~~~~~~~~~~~~~~~~~~~~~~~~~
426+
427+
If you want to support your own custom DSN (``acme://...``), you can create a
428+
custom transport factory. To do so, create a class that implements
429+
:class:`Symfony\\Component\\Mailer\\Transport\\TransportFactoryInterface` or, if
430+
you prefer, extend the :class:`Symfony\\Component\\Mailer\\Transport\\AbstractTransportFactory`
431+
class to save some boilerplate code::
432+
433+
// src/Mailer/AcmeTransportFactory.php
434+
final class AcmeTransportFactory extends AbstractTransportFactory
435+
{
436+
public function create(Dsn $dsn): TransportInterface
437+
{
438+
// parse the given DSN, extract data/credentials from it
439+
// and then, create and return the transport
440+
}
441+
442+
protected function getSupportedSchemes(): array
443+
{
444+
// this supports DSN starting with `acme://`
445+
return ['acme'];
446+
}
447+
}
448+
449+
After creating the custom transport class, register it as a service in your
450+
application and :doc:`tag it </service_container/tags>` with the
451+
``mailer.transport_factory`` tag.
452+
424453
Creating & Sending Messages
425454
---------------------------
426455

0 commit comments

Comments
 (0)