Horde_Smtp_Exception::setSmtpCode PHP Method

setSmtpCode() public method

Set the SMTP reply code.
public setSmtpCode ( integer $smtpcode )
$smtpcode integer SMTP reply code.
    public function setSmtpCode($smtpcode)
    {
        $this->_enhancedcode = null;
        $this->code = 0;
        $this->_smtpcode = $smtpcode;
        /* Any code not listed here will get the details of the error message
         * as returned from the server.
         * Need to store $code/$message here because getCode()/getMessage() is
         * declared final in the parent class and we can not alter on-demand
         * at that location (darn). */
        switch ($smtpcode) {
            case 450:
                $this->code = self::MAILBOX_UNAVAILABLE;
                $this->message = Horde_Smtp_Translation::t("Mailbox unavailable.");
                return;
            case 452:
                $this->code = self::INSUFFICIENT_STORAGE;
                $this->message = Horde_Smtp_Translation::t("Insufficient system storage.");
                return;
            case 454:
                $this->code = self::LOGIN_TLSFAILURE;
                $this->message = Horde_Smtp_Translation::t("Could not open secure TLS connection to the server.");
                return;
            case 530:
                $this->code = self::LOGIN_REQUIREAUTHENTICATION;
                $this->message = Horde_Smtp_Translation::t("Server requires authentication.");
                return;
            case 550:
                $this->code = self::MAILBOX_UNAVAILABLE;
                $this->message = Horde_Smtp_Translation::t("Message could not be delivered - the address was not found, is unknown, or is not receiving messages.");
                return;
            case 551:
                $this->code = self::UNKNOWN_LOCAL_USER;
                return;
            case 552:
                $this->code = self::OVERQUOTA;
                return;
            case 554:
                $this->code = self::DISCONNECT;
                $this->message = Horde_Smtp_Translation::t("Server is not accepting SMTP connections.");
                return;
        }
        $str_code = strval($smtpcode);
        switch ($str_code[1]) {
            case '0':
                $this->code = self::CATEGORY_SYNTAX;
                break;
            case '1':
                $this->code = self::CATEGORY_INFORMATIONAL;
                break;
            case '2':
                $this->code = self::CATEGORY_CONNECTIONS;
                break;
            case '5':
                $this->code = self::CATEGORY_MAILSYSTEM;
                break;
        }
    }

Usage Example

Example #1
0
File: Lmtp.php Project: horde/horde
 /**
  */
 protected function _processData($recipients)
 {
     /* RFC 2033 [4.2/4.3]: there is one response for each successful
      * recipient, so need to iterate through the array. If no successful
      * recipients found, throw an exception. */
     $out = array();
     $success = false;
     foreach ($recipients as $val) {
         try {
             $this->_getResponse(250);
             $out[$val] = $success = true;
         } catch (Horde_Smtp_Exception $e) {
             $out[$val] = $e;
         }
     }
     if (!$success) {
         $e = new Horde_Smtp_Exception('Sending to all recipients failed.');
         $e->setSmtpCode(550);
         throw $e;
     }
     return $out;
 }
All Usage Examples Of Horde_Smtp_Exception::setSmtpCode