code: private function attachMailListeners(
          EventsCapableInterface $service,
          ContainerInterface $container,
          array $mailOptions
      ): void {
          $listeners = (array) ($mailOptions['mail_listeners'] ?? []);
          if (empty($listeners)) {
              return;
          }
  
          $definitions = [];
          $eventManager = $service->getEventManager();
          foreach ($listeners as $listener) {
              $this->addDefinitions($definitions, $listener, $eventManager);
          }
  
          // Attach lazy event listeners if any
          if (! empty($definitions)) {
              (new LazyListenerAggregate($definitions, $container))->attach($eventManager);
          }
      }
docs: Attaches the preconfigured mail listeners to the mail service
  
  @param EventsCapableInterface $service
  @param ContainerInterface $container
  @param array $mailOptions
  @throws InvalidArgumentException
  @throws Exception\InvalidArgumentException
  @throws NotFoundExceptionInterface