private function createMailer(Swift_Transport $transport, array $config): MailerContract
    {
        $swiftMailer = $this->createSwiftMailer($transport);

        if ($this->queueManager !== null) {
            $mailer = new QueueMailer($swiftMailer, $this->queueManager, $config);
        } else {
            $mailer = new Mailer($swiftMailer, $config);
        }

        if ($this->container !== null) {
            $mailer->setContainer($this->container);
        }

        if ($this->viewFactory !== null) {
            $mailer->setViewFactory($this->viewFactory);
        }

        if ($this->eventManager !== null) {
            $mailer->setEventManager($this->eventManager);
        }

        // Next we will set all of the global addresses on this mailer, which allows
        // for easy unification of all "from" addresses as well as easy debugging
        // of sent messages since they get be sent into a single email address.
        foreach (['from', 'reply_to', 'to'] as $type) {
            $this->setGlobalAddress($mailer, $type);
        }

        return $mailer;
    }