{"record":{"id":"01d18457441a8971","repo":"semaphoreui/semaphore","slug":"unexpected-server-challenge-s","errorCode":null,"errorMessage":"unexpected server challenge: %s","messagePattern":"unexpected server challenge: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"util/mailer/auth.go","lineNumber":64,"sourceCode":"}\n\nfunc (a *plainOrLoginAuth) Next(fromServer []byte, more bool) ([]byte, error) {\n\tif !more {\n\t\treturn nil, nil\n\t}\n\n\tif a.authMethod == \"PLAIN\" {\n\t\t// We've already sent everything.\n\t\treturn nil, errors.New(\"unexpected server challenge\")\n\t}\n\n\tswitch {\n\tcase bytes.Equal(fromServer, []byte(\"Username:\")):\n\t\treturn []byte(a.username), nil\n\tcase bytes.Equal(fromServer, []byte(\"Password:\")):\n\t\treturn []byte(a.password), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unexpected server challenge: %s\", fromServer)\n\t}\n}\n","sourceCodeStart":46,"sourceCodeEnd":67,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/util/mailer/auth.go#L46-L67","documentation":"During LOGIN-style auth, Next expects the server challenge to be exactly 'Username:' or 'Password:'. Any other prompt (localized text, extra whitespace, different wording) falls through to this error, which includes the offending challenge bytes.","triggerScenarios":"SMTP server performs LOGIN auth but prompts with non-standard strings (e.g. 'Username:', lowercase, localized messages, or base64-wrapped prompts), so bytes.Equal matches neither expected literal.","commonSituations":"Non-English SMTP servers (localized LOGIN prompts); Exchange/other servers using 'Username' without colon; custom relays with slightly different challenge text.","solutions":["Switch to a mechanism with fixed semantics (PLAIN over TLS) instead of relying on LOGIN prompt text.","Extend the LOGIN handling to match the actual prompts your server sends (case-insensitive/prefix match).","Check the error message for the exact challenge string and align either the server locale or the client matching."],"exampleFix":"// before\ncase bytes.Equal(fromServer, []byte(\"Username:\")):\n    return []byte(a.username), nil\n// after\nswitch {\ncase bytes.Contains(bytes.ToLower(fromServer), []byte(\"user\")):\n    return []byte(a.username), nil\ncase bytes.Contains(bytes.ToLower(fromServer), []byte(\"pass\")):\n    return []byte(a.password), nil\n}","handlingStrategy":"try-catch","validationCode":"// probe the server's LOGIN prompts before auth, or pin the mechanism\nif serverUsesLocalizedLoginPrompts {\n    return errors.New(\"server LOGIN prompts are non-standard; use PLAIN over TLS instead\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := auth.Next(fromServer, true)\nif err != nil && strings.HasPrefix(err.Error(), \"unexpected server challenge:\") {\n    // log err for the exact prompt text; switch to PLAIN over TLS or patch prompt matching\n    return fmt.Errorf(\"unsupported LOGIN prompt from server: %w\", err)\n}","preventionTips":["Prefer PLAIN over TLS instead of LOGIN to avoid dependence on prompt text.","Set the SMTP server locale to English or match its exact prompt strings in the client.","Include the challenge text (already in the error) in logs when diagnosing relay incompatibilities.","Test SMTP auth against the actual production server, including localized configurations."],"tags":["smtp","auth","login","protocol"],"backgroundTag":"unexpected-response-shape","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}