{"record":{"id":"d0f93feffcba861f","repo":"appwrite/appwrite","slug":"authentication-failed-exception-reply","errorCode":null,"errorMessage":"Authentication failed: {$exception->reply}","messagePattern":"Authentication failed: (.+?)","errorType":"exception","errorClass":"AuthenticationException","httpStatus":null,"severity":"error","filePath":"packages/smtp/src/Client.php","lineNumber":345,"sourceCode":"            $command .= ' ' . ($initial === '' ? '=' : base64_encode($initial));\n        }\n\n        try {\n            $reply = $this->command($command, [235, 334]);\n\n            for ($challenges = 0; $reply->code === 334; ++$challenges) {\n                if ($challenges >= self::MAX_CHALLENGES) {\n                    throw new AuthenticationException('The server kept challenging');\n                }\n\n                $challenge = base64_decode($reply->text(), true);\n                $reply = $this->command(\n                    base64_encode($authenticator->respond($challenge === false ? '' : $challenge, $challenges)),\n                    [235, 334],\n                );\n            }\n        } catch (TransactionException $exception) {\n            throw new AuthenticationException(\n                \"Authentication failed: {$exception->reply}\",\n                $exception->reply->code,\n                $exception,\n            );\n        }\n    }\n\n    /**\n     * MAIL FROM parameters, decided by what the server advertised.\n     *\n     * @param  string|iterable<string>  $content\n     */\n    private function parameters(Envelope $envelope, string|iterable $content): string\n    {\n        $parameters = '';\n\n        if (\\is_string($content)) {\n            $size = \\strlen($content);","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/appwrite/appwrite/blob/7eab5f1970bacb06f8cce069c27b7d14a4178153/packages/smtp/src/Client.php#L327-L363","documentation":"When the SASL exchange fails with a TransactionException (the server returned an error reply to an AUTH command), Client::attempt() wraps it as AuthenticationException(\"Authentication failed: {reply}\") preserving the reply code, so credential/authorization rejections surface as a typed auth failure with the server's message.","triggerScenarios":"Server responds 535 (authentication credentials invalid), 534 (mechanism too weak), 530 (required authentication), or any non-235 final reply during the AUTH conversation initiated by start() with credentials.","commonSituations":"Wrong username/password in env config; account locked or disabled on the mail server; OAuth token expired for XOAUTH2; password with special characters mis-encoded in config; IP not permitted to authenticate.","solutions":["Read the wrapped reply code/text in the exception (e.g. 535 = bad credentials).","Verify SMTP username and password, and that the account is active and allowed to send.","For XOAUTH2-style flows, refresh the access token before connecting.","Confirm TLS is established if the server requires it before accepting credentials.","Test the credentials against the server with an independent tool."],"exampleFix":"// before\n$client->start($user, $password);\n// after\ntry {\n    $client->start($user, $password);\n} catch (AuthenticationException $e) {\n    logger()->error('SMTP auth failed', ['reply' => $e->reply->code]);\n}","handlingStrategy":"try-catch","validationCode":"if ($user === '' || $secret === '') {\n    throw new RuntimeException('SMTP credentials missing');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $client->start($user, $secret);\n} catch (AuthenticationException $e) {\n    // $e->reply->code: 535 = invalid credentials, 534 = weak mechanism\n    log_error('SMTP auth failed', ['code' => $e->reply->code]);\n}","preventionTips":["Store SMTP credentials in env/secret manager, verify with a smoke test on deploy","Refresh OAuth tokens before connecting when using token-based auth","Confirm the mail account is active and permitted to relay"],"tags":["smtp","authentication","credentials"],"backgroundTag":"authentication-failed","analyzedSha":"7eab5f1970bacb06f8cce069c27b7d14a4178153","analyzedAt":"2026-09-23T00:38:38.905Z","contentChangedAt":"2026-09-23T00:38:38.905Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}