{"record":{"id":"3cef264eb9c5a599","repo":"SigNoz/signoz","slug":"codeinvalidinput-3cef26","errorCode":"CodeInvalidInput","errorMessage":"unexpected server challenge","messagePattern":"unexpected server challenge","errorType":"error_code","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/smtp/client/auth.go","lineNumber":31,"sourceCode":"}\n\nfunc LoginAuth(username, password string) smtp.Auth {\n\treturn &loginAuth{username, password}\n}\n\nfunc (auth *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {\n\treturn \"LOGIN\", []byte{}, nil\n}\n\nfunc (auth *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {\n\tif more {\n\t\tswitch strings.ToLower(string(fromServer)) {\n\t\tcase \"username:\":\n\t\t\treturn []byte(auth.username), nil\n\t\tcase \"password:\":\n\t\t\treturn []byte(auth.password), nil\n\t\tdefault:\n\t\t\treturn nil, errors.New(errors.TypeInvalidInput, errors.CodeInvalidInput, \"unexpected server challenge\")\n\t\t}\n\t}\n\treturn nil, nil\n}\n","sourceCodeStart":13,"sourceCodeEnd":36,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/smtp/client/auth.go#L13-L36","documentation":"smtp/client's LOGIN auth implementation answers the server's challenge prompts ('username:' / 'password:'). If the server sends any other challenge string, the client cannot respond and aborts with 'unexpected server challenge'.","triggerScenarios":"Authenticating to an SMTP server using LOGIN auth where the server sends a non-standard prompt (different casing is handled, but different wording is not), or the server sends an extra prompt after username/password.","commonSituations":"Non-compliant or proxy SMTP servers (some Exchange front-ends, load balancers) that phrase prompts differently; servers that request additional steps like 'password again'.","solutions":["Use PLAIN or CRAM-MD5 auth instead of LOGIN if the server advertises it","Inspect the raw SMTP dialogue (enable client debug logging) to see the actual challenge string","Add the observed challenge to the switch in auth.go Next (if you control the fork)"],"exampleFix":"// before\nclient.SetAuth(smtp.LoginAuth(user, pass))\n\n// after\nclient.SetAuth(smtp.PlainAuth(\"\", user, pass, host))","handlingStrategy":"fallback","validationCode":"// prefer PLAIN when the server offers it, avoiding LOGIN quirks\nif strings.Contains(ehloAuthLine, \"PLAIN\") {\n    auth = plainAuth\n}","typeGuard":null,"tryCatchPattern":"if err := client.Do(ctx); err != nil {\n    if strings.Contains(err.Error(), \"unexpected server challenge\") {\n        // retry with PLAIN/CRAM-MD5 auth mechanism\n    }\n}","preventionTips":["Test auth against the exact SMTP server version in staging","Capture the SMTP dialogue when integrating with non-standard servers"],"tags":["go","smtp","login-auth","protocol-mismatch"],"backgroundTag":"smtp-auth-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}