Esempio n. 1
0
    /**
     * Prepares a transport using the TYPO3_CONF_VARS configuration
     *
     * Used options:
     * $TYPO3_CONF_VARS['MAIL']['transport'] = 'smtp' | 'sendmail' | 'mail' | 'mbox'
     *
     * $TYPO3_CONF_VARS['MAIL']['transport_smtp_server'] = 'smtp.example.org';
     * $TYPO3_CONF_VARS['MAIL']['transport_smtp_port'] = '25';
     * $TYPO3_CONF_VARS['MAIL']['transport_smtp_encrypt'] = FALSE; # requires openssl in PHP
     * $TYPO3_CONF_VARS['MAIL']['transport_smtp_username'] = '******';
     * $TYPO3_CONF_VARS['MAIL']['transport_smtp_password'] = '******';
     *
     * $TYPO3_CONF_VARS['MAIL']['transport_sendmail_command'] = '/usr/sbin/sendmail -bs'
     *
     * @throws \TYPO3\CMS\Core\Exception
     * @throws RuntimeException
     */
    private function initializeTransport()
    {
        switch ($this->mailSettings['transport']) {
            case 'smtp':
                // Get settings to be used when constructing the transport object
                list($host, $port) = preg_split('/:/', $this->mailSettings['transport_smtp_server']);
                if ($host === '') {
                    throw new \TYPO3\CMS\Core\Exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_smtp_server\'] needs to be set when transport is set to "smtp"', 1291068606);
                }
                if ($port === '') {
                    $port = '25';
                }
                $useEncryption = $this->mailSettings['transport_smtp_encrypt'] ? $this->mailSettings['transport_smtp_encrypt'] : NULL;
                // Create our transport
                $this->transport = \Swift_SmtpTransport::newInstance($host, $port, $useEncryption);
                // Need authentication?
                $username = $this->mailSettings['transport_smtp_username'];
                if ($username !== '') {
                    $this->transport->setUsername($username);
                }
                $password = $this->mailSettings['transport_smtp_password'];
                if ($password !== '') {
                    $this->transport->setPassword($password);
                }
                break;
            case 'sendmail':
                $sendmailCommand = $this->mailSettings['transport_sendmail_command'];
                if (empty($sendmailCommand)) {
                    throw new \TYPO3\CMS\Core\Exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_sendmail_command\'] needs to be set when transport is set to "sendmail"', 1291068620);
                }
                // Create our transport
                $this->transport = \Swift_SendmailTransport::newInstance($sendmailCommand);
                break;
            case 'mbox':
                $mboxFile = $this->mailSettings['transport_mbox_file'];
                if ($mboxFile == '') {
                    throw new \TYPO3\CMS\Core\Exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_mbox_file\'] needs to be set when transport is set to "mbox"', 1294586645);
                }
                // Create our transport
                $this->transport = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MboxTransport', $mboxFile);
                break;
            case 'mail':
                // Create the transport, no configuration required
                $this->transport = \Swift_MailTransport::newInstance();
                break;
            default:
                // Custom mail transport
                $customTransport = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->mailSettings['transport'], $this->mailSettings);
                if ($customTransport instanceof \Swift_Transport) {
                    $this->transport = $customTransport;
                } else {
                    throw new \RuntimeException($this->mailSettings['transport'] . ' is not an implementation of \\Swift_Transport,
						but must implement that interface to be used as a mail transport.', 1323006478);
                }
        }
        return;
    }
 /**
  * Prepares a transport using the TYPO3_CONF_VARS configuration
  *
  * Used options:
  * $TYPO3_CONF_VARS['MAIL']['transport'] = 'smtp' | 'sendmail' | 'mail' | 'mbox'
  *
  * $TYPO3_CONF_VARS['MAIL']['transport_smtp_server'] = 'smtp.example.org';
  * $TYPO3_CONF_VARS['MAIL']['transport_smtp_port'] = '25';
  * $TYPO3_CONF_VARS['MAIL']['transport_smtp_encrypt'] = FALSE; # requires openssl in PHP
  * $TYPO3_CONF_VARS['MAIL']['transport_smtp_username'] = '******';
  * $TYPO3_CONF_VARS['MAIL']['transport_smtp_password'] = '******';
  *
  * $TYPO3_CONF_VARS['MAIL']['transport_sendmail_command'] = '/usr/sbin/sendmail -bs'
  *
  * @throws t3lib_exception
  */
 private function initializeTransport()
 {
     $mailSettings = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
     switch ($mailSettings['transport']) {
         case 'smtp':
             // Get settings to be used when constructing the transport object
             list($host, $port) = preg_split('/:/', $mailSettings['transport_smtp_server']);
             if ($host === '') {
                 throw new t3lib_exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_smtp_server\'] needs to be set when transport is set to "smtp"', 1291068606);
             }
             if ($port === '') {
                 $port = '25';
             }
             $useEncryption = $mailSettings['transport_smtp_encrypt'] ? TRUE : FALSE;
             // Create our transport
             $this->transport = Swift_SmtpTransport::newInstance($host, $port, $useEncryption);
             // Need authentication?
             $username = $mailSettings['transport_smtp_username'];
             if ($username !== '') {
                 $this->transport->setUsername($username);
             }
             $password = $mailSettings['transport_smtp_password'];
             if ($password !== '') {
                 $this->transport->setPassword($password);
             }
             break;
         case 'sendmail':
             $sendmailCommand = $mailSettings['transport_sendmail_command'];
             if ($sendmailCommand === '') {
                 throw new t3lib_exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_sendmail_command\'] needs to be set when transport is set to "sendmail"', 1291068620);
             }
             // Create our transport
             $this->transport = Swift_SendmailTransport::newInstance($sendmailCommand);
             break;
         case 'mbox':
             $mboxFile = $mailSettings['transport_mbox_file'];
             if ($mboxFile == '') {
                 throw new t3lib_exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_mbox_file\'] needs to be set when transport is set to "mbox"');
             }
             // Create our transport
             $this->transport = t3lib_div::makeInstance('t3lib_mail_mboxtransport', $mboxFile);
             break;
         case 'mail':
         default:
             // Create the transport, no configuration required
             $this->transport = Swift_MailTransport::newInstance();
             break;
     }
     return;
 }
Esempio n. 3
0
 /**
  * Set transport
  *
  * @param string $type
  * @param array $options
  * @return Omnimessage\Service\Email
  */
 public function setTransport($type = 'smtp', $options = array())
 {
     if (!in_array($type, array_keys(self::$transports))) {
         throw new Exception('Email Transport: ' . $type . ' is not available');
     }
     switch ($type) {
         case 'smtp':
             $class = '\\' . self::$transports['smtp'];
             if (!isset($options['host']) && !isset($options['port'])) {
                 throw new Exception('Email Transport smtp requires host & port options');
             }
             $this->transport = $class::newInstance($options['host'], $options['port']);
             if (isset($options['username']) && isset($options['password'])) {
                 $this->transport->setUsername($options['username'])->setPassword($options['password']);
             }
             if (isset($options['encryption']) && in_array($options['encryption'], array('ssl', 'tls'))) {
                 $this->transport->setEncryption($options['encryption']);
             }
             break;
         case 'send_mail':
             $class = '\\' . self::$transports['send_mail'];
             $cmd = '/usr/sbin/sendmail -bs';
             if (!empty($options['cmd'])) {
                 $cmd = $options['cmd'];
             }
             $this->transport = $class::newInstance($cmd);
             break;
         case 'mail':
             $class = '\\' . self::$transports['mail'];
             $this->transport = $class::newInstance();
             break;
         default:
             throw new Exception('Email transport: ' . $type . ' is not supported');
     }
     return $this;
 }