Skip to content

Commit 416df37

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Mailer] Add custom transport factories
2 parents 4b7c2ce + d413ef9 commit 416df37

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
@@ -389,6 +389,35 @@ Other Options
389389

390390
$dsn = 'smtps://smtp.example.com?max_per_second=2'
391391

392+
Custom Transport Factories
393+
~~~~~~~~~~~~~~~~~~~~~~~~~~
394+
395+
If you want to support your own custom DSN (``acme://...``), you can create a
396+
custom transport factory. To do so, create a class that implements
397+
:class:`Symfony\\Component\\Mailer\\Transport\\TransportFactoryInterface` or, if
398+
you prefer, extend the :class:`Symfony\\Component\\Mailer\\Transport\\AbstractTransportFactory`
399+
class to save some boilerplate code::
400+
401+
// src/Mailer/AcmeTransportFactory.php
402+
final class AcmeTransportFactory extends AbstractTransportFactory
403+
{
404+
public function create(Dsn $dsn): TransportInterface
405+
{
406+
// parse the given DSN, extract data/credentials from it
407+
// and then, create and return the transport
408+
}
409+
410+
protected function getSupportedSchemes(): array
411+
{
412+
// this supports DSN starting with `acme://`
413+
return ['acme'];
414+
}
415+
}
416+
417+
After creating the custom transport class, register it as a service in your
418+
application and :doc:`tag it </service_container/tags>` with the
419+
``mailer.transport_factory`` tag.
420+
392421
Creating & Sending Messages
393422
---------------------------
394423

0 commit comments

Comments
 (0)