Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eb4655

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Mailer] Add custom transport factories
2 parents 485b520 + 3d3bdaa commit 3eb4655

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
@@ -397,6 +397,35 @@ Other Options
397397

398398
The ``max_per_second`` option was introduced in Symfony 6.2.
399399

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

0 commit comments

Comments
 (0)