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);
        }
    }