Author: Chris Corbyn
Inheritance: implements Swift_Transport
 /**
  * Sets the local domain based on the current request context.
  */
 public function configure(\Swift_Transport_AbstractSmtpTransport $transport)
 {
     if ($this->localDomain) {
         $transport->setLocalDomain($this->localDomain);
     } elseif ($this->requestContext) {
         $transport->setLocalDomain($this->requestContext->getHost());
     }
 }
Esempio n. 2
0
 /** Overridden to perform EHLO instead */
 protected function _doHeloCommand()
 {
     try {
         $response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->_domain), array(250));
     } catch (Swift_TransportException $e) {
         return parent::_doHeloCommand();
     }
     if ($this->_params['tls']) {
         try {
             $this->executeCommand("STARTTLS\r\n", array(220));
             if (!$this->_buffer->startTLS()) {
                 throw new Swift_TransportException('Unable to connect with TLS encryption');
             }
             try {
                 $response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->_domain), array(250));
             } catch (Swift_TransportException $e) {
                 return parent::_doHeloCommand();
             }
         } catch (Swift_TransportException $e) {
             $this->_throwException($e);
         }
     }
     $this->_capabilities = $this->_getCapabilities($response);
     $this->_setHandlerParams();
     foreach ($this->_getActiveHandlers() as $handler) {
         $handler->afterEhlo($this);
     }
 }
Esempio n. 3
0
 /** Overridden to perform EHLO instead */
 protected function _doHeloCommand()
 {
     try {
         $response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->_domain), array(250));
         $this->_capabilities = $this->_getCapabilities($response);
         $this->_setHandlerParams();
         foreach ($this->_getActiveHandlers() as $handler) {
             $handler->afterEhlo($this);
         }
     } catch (Swift_TransportException $e) {
         parent::_doHeloCommand();
     }
 }
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  *
  * The return value is the number of recipients who were accepted for delivery.
  * NOTE: If using 'sendmail -t' you will not be aware of any failures until
  * they bounce (i.e. send() will always return 100% success).
  *
  * @param Swift_Mime_Message $message
  * @param string[]           $failedRecipients An array of failures by-reference
  *
  * @return int
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $failedRecipients = (array) $failedRecipients;
     $command = $this->getCommand();
     $buffer = $this->getBuffer();
     if (false !== strpos($command, ' -t')) {
         if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
             $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
             if ($evt->bubbleCancelled()) {
                 return 0;
             }
         }
         if (false === strpos($command, ' -f')) {
             $command .= ' -f' . escapeshellarg($this->_getReversePath($message));
         }
         $buffer->initialize(array_merge($this->_params, array('command' => $command)));
         if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
             $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
         } else {
             $buffer->setWriteTranslations(array("\r\n" => "\n"));
         }
         $count = count((array) $message->getTo()) + count((array) $message->getCc()) + count((array) $message->getBcc());
         $message->toByteStream($buffer);
         $buffer->flushBuffers();
         $buffer->setWriteTranslations(array());
         $buffer->terminate();
         if ($evt) {
             $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
             $evt->setFailedRecipients($failedRecipients);
             $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
         }
         $message->generateId();
     } elseif (false !== strpos($command, ' -bs')) {
         $count = parent::send($message, $failedRecipients);
     } else {
         $this->_throwException(new Swift_TransportException('Unsupported sendmail command flags [' . $command . ']. ' . 'Must be one of "-bs" or "-t" but can include additional flags.'));
     }
     return $count;
 }
Esempio n. 5
0
 /**
  * Run a command against the buffer, expecting the given response codes.
  *
  * If no response codes are given, the response will not be validated.
  * If codes are given, an exception will be thrown on an invalid response.
  *
  * @param string $command
  * @param int[] $codes
  * @param string[] $failures An array of failures by-reference
  *
  * @return string
  */
 public function executeCommand($command, $codes = array(), &$failures = null)
 {
     $failures = (array) $failures;
     $stopSignal = false;
     $response = null;
     foreach ($this->_getActiveHandlers() as $handler) {
         $response = $handler->onCommand($this, $command, $codes, $failures, $stopSignal);
         if ($stopSignal) {
             return $response;
         }
     }
     return parent::executeCommand($command, $codes, $failures);
 }