Skip to content

Commit 1d1eb9c

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [Mailer] Add custom transport factories
2 parents 6536e36 + 416df37 commit 1d1eb9c

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
@@ -401,6 +401,35 @@ Other Options
401401

402402
$dsn = 'smtps://smtp.example.com?max_per_second=2'
403403

404+
Custom Transport Factories
405+
~~~~~~~~~~~~~~~~~~~~~~~~~~
406+
407+
If you want to support your own custom DSN (``acme://...``), you can create a
408+
custom transport factory. To do so, create a class that implements
409+
:class:`Symfony\\Component\\Mailer\\Transport\\TransportFactoryInterface` or, if
410+
you prefer, extend the :class:`Symfony\\Component\\Mailer\\Transport\\AbstractTransportFactory`
411+
class to save some boilerplate code::
412+
413+
// src/Mailer/AcmeTransportFactory.php
414+
final class AcmeTransportFactory extends AbstractTransportFactory
415+
{
416+
public function create(Dsn $dsn): TransportInterface
417+
{
418+
// parse the given DSN, extract data/credentials from it
419+
// and then, create and return the transport
420+
}
421+
422+
protected function getSupportedSchemes(): array
423+
{
424+
// this supports DSN starting with `acme://`
425+
return ['acme'];
426+
}
427+
}
428+
429+
After creating the custom transport class, register it as a service in your
430+
application and :doc:`tag it </service_container/tags>` with the
431+
``mailer.transport_factory`` tag.
432+
404433
Creating & Sending Messages
405434
---------------------------
406435

0 commit comments

Comments
 (0)