src/Utils/SwiftMailer/SmtpTransportMailerFactory.php
public static function factory(SwiftMailerConfigurationInterface $swiftMailerConfiguration)
    {

        // load the transport configuration
        $transportConfiguration = $swiftMailerConfiguration->getTransport();

        // load the transport factory
        $transportFactory = $transportConfiguration->getTransportFactory();

        // load the SMTP host from the configuration
        $smtpHost = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_HOST)) {
            $smtpHost = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_HOST);
        }

        // load the SMTP port from the configuration
        $smtpPort = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_PORT)) {
            $smtpPort = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_PORT);
        }

        // load the SMTP security from the configuration
        $smtpSecurity = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_SECURITY)) {
            $smtpSecurity = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_SECURITY);
        }

        // initialize and create the mailer transport instance
        $transport = $transportFactory::newInstance($smtpHost, $smtpPort, $smtpSecurity);

        // query whether or not if a SMTP authentication mode has been specified
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_AUTH_MODE)) {
            // load the authentication mode from the configuration
            $transport->setAuthMode($transportConfiguration->getParam(SwiftMailerKeys::SMTP_AUTH_MODE));
            // set the stream context options, e. g. to allow self signed certificates
            $transport->setStreamOptions(
                array(
                    'ssl' => array(
                        'allow_self_signed' => true,
                        'verify_peer'       => false
                    )
                )
            );

            // load the SMTP username from the configuration
            if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_USERNAME)) {
                $transport->setUsername($transportConfiguration->getParam(SwiftMailerKeys::SMTP_USERNAME));
            }

            // load the SMTP password from the configuration
            if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_PASSWORD)) {
                $transport->setPassword($transportConfiguration->getParam(SwiftMailerKeys::SMTP_PASSWORD));
            }
        }

        // load the mailer factory
        $mailerFactory = $swiftMailerConfiguration->getMailerFactory();

        // initialize, create and return the swift mailer instance
        return $mailerFactory::newInstance($transport);
    }
public static function factory(SwiftMailerConfigurationInterface $swiftMailerConfiguration)
    {

        // load the transport configuration
        $transportConfiguration = $swiftMailerConfiguration->getTransport();

        // load the transport factory
        $transportFactory = $transportConfiguration->getTransportFactory();

        // load the SMTP host from the configuration
        $smtpHost = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_HOST)) {
            $smtpHost = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_HOST);
        }

        // load the SMTP port from the configuration
        $smtpPort = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_PORT)) {
            $smtpPort = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_PORT);
        }

        // load the SMTP security from the configuration
        $smtpSecurity = null;
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_SECURITY)) {
            $smtpSecurity = $transportConfiguration->getParam(SwiftMailerKeys::SMTP_SECURITY);
        }

        // initialize and create the mailer transport instance
        $transport = $transportFactory::newInstance($smtpHost, $smtpPort, $smtpSecurity);

        // query whether or not if a SMTP authentication mode has been specified
        if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_AUTH_MODE)) {
            // load the authentication mode from the configuration
            $transport->setAuthMode($transportConfiguration->getParam(SwiftMailerKeys::SMTP_AUTH_MODE));
            // set the stream context options, e. g. to allow self signed certificates
            $transport->setStreamOptions(
                array(
                    'ssl' => array(
                        'allow_self_signed' => true,
                        'verify_peer'       => false
                    )
                )
            );

            // load the SMTP username from the configuration
            if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_USERNAME)) {
                $transport->setUsername($transportConfiguration->getParam(SwiftMailerKeys::SMTP_USERNAME));
            }

            // load the SMTP password from the configuration
            if ($transportConfiguration->hasParam(SwiftMailerKeys::SMTP_PASSWORD)) {
                $transport->setPassword($transportConfiguration->getParam(SwiftMailerKeys::SMTP_PASSWORD));
            }
        }

        // load the mailer factory
        $mailerFactory = $swiftMailerConfiguration->getMailerFactory();

        // initialize, create and return the swift mailer instance
        return $mailerFactory::newInstance($transport);
    }
Creates a new swift mailer instance based on the passed configuration.

@param \TechDivision\Import\Configuration\SwiftMailerConfigurationInterface $swiftMailerConfiguration The mailer configuration

@return \Swift_Mailer The mailer instance