protected function registerTransportSmtp()
    {
        $config = $this->getConfig();

        /** @var $transport \Swift_SmtpTransport: */
        $transport = $this->getDI()->get('\Swift_SmtpTransport');

        if (isset($config['encryption'])) {
            $transport->setEncryption($config['encryption']);
        }

        if (isset($config['host'])) {
            $transport->setHost($config['host']);
        } else {
            $transport->setHost('localhost');
        }

        if (isset($config['port'])) {
            $transport->setPort($config['port']);
        } else {
            switch ($transport->getEncryption()) {
                case static::ENCRYPTION_SSL:
                    $transport->setPort(465);
                    break;

                case static::ENCRYPTION_TLS:
                    $transport->setPort(587);
                    break;

                default:
                    $transport->setPort(25);
            }
        }

        if (isset($config['auth_mode'])) {
            $transport->setAuthMode($config['auth_mode']);
        }

        if (isset($config['username'])) {
            $transport->setUsername($this->normalizeEmail($config['username']));
        }

        if (isset($config['password'])) {
            $transport->setPassword($config['password']);
        }

        return $transport;
    }