Create an instance of the SMTP Swift Transport driver.

@return SmtpTransport
960475
protected function createSmtpTransport()
    {
        $config = $this->app['config']['mail'];
        // The Swift SMTP transport instance will allow us to use any SMTP backend
        // for delivering mail such as Sendgrid, Amazon SES, or a custom server
        // a developer has available. We will just pass this configured host.
        $transport = SmtpTransport::newInstance(
            $config['host'], $config['port']
        );
        if (isset($config['encryption'])) {
            $transport->setEncryption($config['encryption']);
        }
        // Once we have the transport we will check for the presence of a username
        // and password. If we have it we will set the credentials on the Swift
        // transporter instance so that we'll properly authenticate delivery.
        if (isset($config['username'])) {
            $transport->setUsername($config['username']);
            $transport->setPassword($config['password']);
        }
        if (isset($config['stream'])) {
            $transport->setStreamOptions($config['stream']);
        }
        return $transport;
    }
574156
public function send($transporter='', $options=array())
	{
		$transporter = $transporter ? $transporter : \Config::get('mailer');

		if (is_object($transporter) && ($transporter instanceof \Swift_Transport))
		{
			// We were given a valid tranport mechanisms, so just use it
			$transport = $transporter;
		}
		elseif (is_string($transporter) && self::hasTrasporter($transporter))
		{
			$transport = self::getTrasporter($transporter);
		}
		else
		{
			switch (strtolower($transporter))
			{
				case 'smtp':
					if (!isset($options['host']))
					{
						$options['host'] = \Config::get('smtphost');
					}
					if (!isset($options['port']))
					{
						$options['port'] = \Config::get('smtpport');
					}
					if (!isset($options['username']))
					{
						$options['username'] = \Config::get('smtpuser');
					}
					if (!isset($options['password']))
					{
						$options['password'] = \Config::get('smtppass');
					}

					if (!empty($options))
					{
						$transport = \Swift_SmtpTransport::newInstance($options['host'], $options['port']);
						$transport->setUsername($options['username'])
						          ->setPassword($options['password']);
					}
				break;

				case 'sendmail':
					if (!isset($options['command']))
					{
						$options['command'] = '/usr/sbin/exim -bs';
					}
					$transport = \Swift_SendmailTransport::newInstance($options['command']);
				break;

				case 'mail':
				default:
					$transport = \Swift_MailTransport::newInstance();
					//set mail additional args (mail return path - used for bounces)
					//$transport->setExtraParams('-f hubmail-bounces@' . $_SERVER['HTTP_HOST']);
				break;
			}

			if (!($transport instanceof \Swift_Transport))
			{
				throw new \InvalidArgumentException('Invalid transport specified');
			}
		}

		$mailer = \Swift_Mailer::newInstance($transport);
		$result = $mailer->send($this, $this->_failures);

		if ($result)
		{
			\Log::info(sprintf('Mail sent to %s', json_encode($this->getTo())));
		}
		else
		{
			\Log::error(sprintf('Failed to mail %s', json_encode($this->getTo())));
		}

		return $result;
	}
1338548
public function init()
    {
        if (!class_exists('Swift_MailTransport')) {
            throw new \Exception('SwiftMailer need to be installed');
        }
        $transport = null;
        switch ($this->config['transport']) {
            case self::TRANSPORT_SENDMAIL:
                $transport = new \Swift_SendmailTransport();
                break;
            case self::TRANSPORT_SMTP:
                $transport = (new \Swift_SmtpTransport(isset($this->config['host'])
                            ? $this->config['host'] : 'localhost',
                    isset($this->config['port']) ? $this->config['port'] : 25,
                    isset($this->config['security']) ? $this->config['security']
                            : ''))
                    ->setUsername($this->config['username'])
                    ->setPassword($this->config['password']);
                break;
            case self::TRANSPORT_MAIL:
            default:
                $transport = new \Swift_MailTransport();
        }
        $this->mailer = new \Swift_Mailer($transport);
        return $this;
    }
868567
protected function getMailer()
    {
        $transport = null;
        if ($this->configurationManager->getSetting('mailer.type') === 'sendmail') {
            $transport = \Swift_SendmailTransport::newInstance($this->configurationManager->getSetting('mailer.sendmailCommand'));
        } else if ($this->configurationManager->getSetting('mailer.type') === 'smtp') {
            $host = $this->configurationManager->getSetting('mailer.smtpHost');
            $port = $this->configurationManager->getSetting('mailer.smtpPort');
            $username = $this->configurationManager->getSetting('mailer.smtpUsername');
            $password = $this->configurationManager->getSetting('mailer.smtpPassword');
            
            $transport = \Swift_SmtpTransport::newInstance($host, $port);
            $transport->setUsername($username);
            $transport->setPassword($password);
        }
        
        if ($transport === null) {
            throw new Exception('No mail transport defined. Please check your configuration.');
        }

        return \Swift_Mailer::newInstance($transport);
    }
911225
protected function getTransport()
    {
        if ($this->transport === null) {
            $this->transport = $this->serviceLocator->get('playgroundcore_transport');
        }

        return $this->transport;
    }
286958
public function createSmtpDriver($config = [])
    {
        $config = array_merge(Config::get(), $config);

        $transport = Swift_SmtpTransport::newInstance(
            $config['host'], $config['port'], $config['security']
        );

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

        if (isset($config['stream'])) {
            $transport->setStreamOptions($config['stream']);
        }

        return $transport;
    }
1216180
public static function createTransport($transport, array $config)
    {
        $config = new Structure($config);

        switch ($transport) {
            case 'smtp':
                $instance = \Swift_SmtpTransport::newInstance(
                    $config->get('smtp.host'),
                    $config->get('smtp.port', 2525),
                    $config->get('smtp.security', 'tls')
                )->setUsername($config->get('smtp.username'))
                    ->setPassword($config->get('smtp.password'));

                if ($config->get('smtp.local')) {
                    $instance->setLocalDomain($config->get('local'));
                }

                if (!$config->get('smtp.verify', true)) {
                    $instance->setStreamOptions(['ssl' => ['allow_self_signed' => true, 'verify_peer' => false]]);
                }

                break;

            case 'sendmail':
                $instance = \Swift_SendmailTransport::newInstance($config->get('sendmail'));

                break;

            default:
                $instance = \Swift_MailTransport::newInstance();
        }

        return $instance;
    }
158150
protected function createClient()
    {
        /** @var SSLCertificate $credentials */
        $credentials         = $this->getCredentials();
        $url                 = $this->getServiceURL();
        $transport           = !empty($url['transport']) ? $url['transport'] : self::SECURE_TRANSPORT_DEFAULT;

        $this->serviceClient = new SocketClient($url['host'], $url['port']);
        $this->serviceClient
            ->setTransport($transport)
            ->setContextOptions(array(
                'local_cert' => $credentials->getCertificate(),
                'passphrase' => $credentials->getCertificatePassPhrase(),
            ))
            ->addConnectionFlag(STREAM_CLIENT_PERSISTENT)
            ->setBlockingMode(false)
        ;

        return $this;
    }
290218
protected function getSwiftMailerTransport()
	{
		if ( !$mailer = $this->mailer )
		{
			return null;
		}

		if ( !$swift_mailer = $mailer->getSwiftMailer() )
		{
			return null;
		}

		if ( !is_a( $swift_mailer, '\Swift_Mailer' ) )
		{
			return null;
		}

		return $swift_mailer->getTransport();
	}
29366
protected function registerSwiftTransport()
    {
        switch ($driver = $this->getConfig('driver')) {
            case 'smtp':
                $this->transport = $this->registerTransportSmtp();
                break;

            case 'mail':
                $this->transport = $this->registerTransportMail();
                break;

            case 'sendmail':
                $this->transport = $this->registerTransportSendmail();
                break;

            default:
                throw new \InvalidArgumentException(sprintf('Driver-mail "%s" is not supported', $driver));
        }
    }
561653
protected function createSmtpDriver()
    {
        $config = $this->app->make('config')->get('mail');

        // The Swift SMTP transport instance will allow us to use any SMTP backend
        // for delivering mail such as Sendgrid, Amazon SES, or a custom server
        // a developer has available. We will just pass this configured host.
        $transport = new SmtpTransport($config['host'], $config['port']);

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

        // Once we have the transport we will check for the presence of a username
        // and password. If we have it we will set the credentials on the Swift
        // transporter instance so that we'll properly authenticate delivery.
        if (isset($config['username'])) {
            $transport->setUsername($config['username']);

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

        // Next we will set any stream context options specified for the transport
        // and then return it. The option is not required any may not be inside
        // the configuration array at all so we'll verify that before adding.
        if (isset($config['stream'])) {
            $transport->setStreamOptions($config['stream']);
        }

        return $transport;
    }
1289578
public function send()
    {

        if ($this->Logger->isEnabled()) {

            $this->Logger->debug($this->message->toString());

        }


        //Now check if Swift actually sends it
        if (!$this->testingOnly) {

            //Now check if Swift actually sends it
            $this->getMailer()->send($this->message);

        }
        return $this;

    }
224854
public function getSMTPObject()
    {
        if ($this->_smtp) {
            return $this->_smtp;
        }

        $this->_smtp = new Net_SMTP(
            $this->_params['host'],
            $this->_params['port'],
            $this->_params['localhost']
        );

        /* Set pipelining. */
        if ($this->_params['pipelining']) {
            $this->_smtp->pipelining = true;
        }

        /* If we still don't have an SMTP object at this point, fail. */
        if (!($this->_smtp instanceof Net_SMTP)) {
            throw new Horde_Mail_Exception('Failed to create a Net_SMTP object', self::ERROR_CREATE);
        }

        /* Configure the SMTP connection. */
        if ($this->_params['debug']) {
            $this->_smtp->setDebug(true);
        }

        /* Attempt to connect to the configured SMTP server. */
        $res = $this->_smtp->connect($this->_params['timeout']);
        if ($res instanceof PEAR_Error) {
            $this->_error('Failed to connect to ' . $this->_params['host'] . ':' . $this->_params['port'], $res, self::ERROR_CONNECT);
        }

        /* Attempt to authenticate if authentication has been enabled. */
        if ($this->_params['auth']) {
            $method = is_string($this->_params['auth'])
                ? $this->_params['auth']
                : '';

            $res = $this->_smtp->auth($this->_params['username'], $this->_params['password'], $method);
            if ($res instanceof PEAR_Error) {
                $this->_error("$method authentication failure", $res, self::ERROR_AUTH);
            }
        }

        return $this->_smtp;
    }
981800
public function getSMTPObject()
    {
        if (is_object($this->_smtp) !== false) {
            return $this->_smtp;
        }

        include_once 'Net/SMTP.php';
        $this->_smtp = new Net_SMTP($this->host,
                                     $this->port,
                                     $this->localhost,
                                     $this->pipelining,
                                     0,
                                     $this->socket_options);

        /* If we still don't have an SMTP object at this point, fail. */
        if (is_object($this->_smtp) === false) {
            return PEAR::raiseError('Failed to create a Net_SMTP object',
                                    PEAR_MAIL_SMTP_ERROR_CREATE);
        }

        /* Configure the SMTP connection. */
        if ($this->debug) {
            $this->_smtp->setDebug(true);
        }

        /* Attempt to connect to the configured SMTP server. */
        if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) {
            $error = $this->_error('Failed to connect to ' .
                                   $this->host . ':' . $this->port,
                                   $res);
            return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT);
        }

        /* Attempt to authenticate if authentication has been enabled. */
        if ($this->auth) {
            $method = is_string($this->auth) ? $this->auth : '';

            if (PEAR::isError($res = $this->_smtp->auth($this->username,
                                                        $this->password,
                                                        $method))) {
                $error = $this->_error("$method authentication failure",
                                       $res);
                $this->_smtp->rset();
                return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH);
            }
        }

        return $this->_smtp;
    }
1030592
protected function sendViaSwiftMailer()
    {
        $factory = new MailerFactory($this->config->get('phpci'));
        $mailer = $factory->getSwiftMailerFromConfig();

        $message = \Swift_Message::newInstance($this->subject)
            ->setFrom($this->getFrom())
            ->setTo($this->emailTo)
            ->setBody($this->body);

        if ($this->isHtml) {
            $message->setContentType('text/html');
        }

        if (is_array($this->emailCc) && count($this->emailCc)) {
            $message->setCc($this->emailCc);
        }

        return $mailer->send($message);
    }
839154
public function deliver($swiftMessage, $transport = null)
    {
        // get the transport
        if (!$transport)
            $transport = $this->defaultTransport;
        if (!isset($this->transports[$transport]))
            throw new CException(Yii::t('email', 'Transport :transport is not configured.', array(':transport' => $transport)));

        // get transport options
        $options = $this->transports[$transport];

        // get transport class
        if (isset($options['class'])) {
            $class = $options['class'];
            unset($options['class']);
        } else {
            throw new CException(Yii::t('email', 'Transport :transport does not have a class.', array(':transport' => $transport)));
        }

        // get transport setters
        if (isset($options['setters'])) {
            $setters = $options['setters'];
            unset($options['setters']);
        } else {
            $setters = array();
        }

        // create a new transport using class, options and setters
        $swiftTransport = call_user_func_array($class . '::newInstance', $options);
        foreach ($setters as $k => $v) {
            call_user_func_array(array($swiftTransport, 'set' . ucfirst($k)), array($v));
        }

        // send the message using the transport
        return Swift_Mailer::newInstance($swiftTransport)->send($swiftMessage);
    }
29776
public function create()
    {
        $instance = self::createRefundTransaction($this);
        $this->setId($instance->getId());
        return $instance;
    }