protected function smtp_connect()
	{
		// re-use the existing connection
		if ( ! empty($this->smtp_connection))
		{
			return;
		}

		// add a transport if not given
		if (strpos($this->config['smtp']['host'], '://') === false)
		{
			$this->config['smtp']['host'] = 'tcp://'.$this->config['smtp']['host'];
		}

		$this->smtp_connection = stream_socket_client(
			$this->config['smtp']['host'].':'.$this->config['smtp']['port'],
			$error_number,
			$error_string,
			$this->config['smtp']['timeout']
		);

		if(empty($this->smtp_connection))
		{
			throw new \SmtpConnectionException('Could not connect to SMTP: ('.$error_number.') '.$error_string);
		}

		// Clear the smtp response
		$this->smtp_get_response();

		// Just say hello!
		try
		{
			$this->smtp_send('EHLO'.' '.\Input::server('SERVER_NAME', 'localhost.local'), 250);
		}
		catch(\SmtpCommandFailureException $e)
		{
			// Didn't work? Try HELO
			$this->smtp_send('HELO'.' '.\Input::server('SERVER_NAME', 'localhost.local'), 250);
		}

		// Enable TLS encryption if needed, and we're connecting using TCP
		if (\Arr::get($this->config, 'smtp.starttls', false) and strpos($this->config['smtp']['host'], 'tcp://') === 0)
		{
			try
			{
				$this->smtp_send('STARTTLS', 220);
				if ( ! stream_socket_enable_crypto($this->smtp_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
				{
					throw new \SmtpConnectionException('STARTTLS failed, Crypto client can not be enabled.');
    			}
			}
			catch(\SmtpCommandFailureException $e)
			{
				throw new \SmtpConnectionException('STARTTLS failed, invalid return code received from server.');
			}

			// Say hello again, the service list might be updated (see RFC 3207 section 4.2)
			try
			{
				$this->smtp_send('EHLO'.' '.\Input::server('SERVER_NAME', 'localhost.local'), 250);
			}
			catch(\SmtpCommandFailureException $e)
			{
				// Didn't work? Try HELO
				$this->smtp_send('HELO'.' '.\Input::server('SERVER_NAME', 'localhost.local'), 250);
			}
		}

		try
		{
			$this->smtp_send('HELP', 214);
		}
		catch(\SmtpCommandFailureException $e)
		{
			// Let this pass as some servers don't support this.
		}
	}