Allow custom TransportFactory

Created on 10 January 2023, almost 2 years ago
Updated 25 January 2023, almost 2 years ago

Problem/Motivation

I tried to add a new TransportFactory and Transport class to handle a new DSN like foo://

This is possible with symfony mailer by following a few steps:

final class FooTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        return new FooTransport();
    }

    protected function getSupportedSchemes(): array
    {
        return ['foo'];
    }
}
services:
  mailer.transport_factory.foo:
    class: App\FooTransportFactory
    parent: mailer.transport_factory.abstract
    tags:
      - {name: mailer.transport_factory}

For now, the Drupal "MailerTransport" plugin allows us to define a new DSN, it is usable in the configuration, but that's all.
Symfony Mailer crash saying "Unknow Dsn scheme"

Is there a way to do it?

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France damien laguerre

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review almost 2 years ago
  • 🇬🇧United Kingdom adamps

    Great thanks. I have updated the MR with two changes:

    1. For performance, Mailer should create the Transport object once during the constructor, not once per mail sent.
    2. I discovered that in Drupal the service_collector tag corresponds to tagged_iterator in Symfony. Use this instead of creating a compiler pass.

    Please can you review and check it works in your system?

  • 🇫🇷France damien laguerre

    Great!

    2. I discovered that in Drupal the service_collector tag corresponds to tagged_iterator in Symfony. Use this instead of creating a compiler pass.

    I first tried this way, but it could not be used with all the Symfony services I defined the first time.
    Now it's really the best solution.

    I did some tests and everything works fine!

  • Status changed to Fixed almost 2 years ago
  • 🇬🇧United Kingdom adamps

    Great thanks

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024