Allow custom TransportFactory

Created on 10 January 2023, over 1 year ago
Updated 25 January 2023, over 1 year 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 over 1 year 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 over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Great thanks

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

Production build 0.69.0 2024