Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [Mailer] Add custom transport factories
  • Loading branch information
javiereguiluz committed Jan 18, 2024
2 parents 485b520 + 3d3bdaa commit 3eb4655
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,35 @@ Other Options

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

Custom Transport Factories
~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want to support your own custom DSN (``acme://...``), you can create a
custom transport factory. To do so, create a class that implements
:class:`Symfony\\Component\\Mailer\\Transport\\TransportFactoryInterface` or, if
you prefer, extend the :class:`Symfony\\Component\\Mailer\\Transport\\AbstractTransportFactory`
class to save some boilerplate code::

// src/Mailer/AcmeTransportFactory.php
final class AcmeTransportFactory extends AbstractTransportFactory
{
public function create(Dsn $dsn): TransportInterface
{
// parse the given DSN, extract data/credentials from it
// and then, create and return the transport
}

protected function getSupportedSchemes(): array
{
// this supports DSN starting with `acme://`
return ['acme'];
}
}

After creating the custom transport class, register it as a service in your
application and :doc:`tag it </service_container/tags>` with the
``mailer.transport_factory`` tag.

Creating & Sending Messages
---------------------------

Expand Down

0 comments on commit 3eb4655

Please sign in to comment.