{"record":{"id":"b154f590052fb94d","repo":"jstedfast/MailKit","slug":"unexpected-response-from-server-0","errorCode":null,"errorMessage":"Unexpected response from server: {0}","messagePattern":"Unexpected response from server: (.+?)","errorType":"exception","errorClass":"Pop3ProtocolException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Pop3/Pop3Client.cs","lineNumber":696,"sourceCode":"\t\t\t}\n\n\t\t\tvoid OnDataReceived (Pop3Engine pop3, Pop3Command pc, string text, CancellationToken cancellationToken)\n\t\t\t{\n\t\t\t\tpop3.CheckConnected ();\n\n\t\t\t\twhile (pc.Status == Pop3CommandStatus.Continue && !mechanism.IsAuthenticated) {\n\t\t\t\t\tvar challenge = mechanism.Challenge (text, cancellationToken);\n\t\t\t\t\tvar buf = Encoding.ASCII.GetBytes (challenge + \"\\r\\n\");\n\n\t\t\t\t\tpop3.Stream.Write (buf, 0, buf.Length, cancellationToken);\n\t\t\t\t\tpop3.Stream.Flush (cancellationToken);\n\n\t\t\t\t\tvar response = pop3.ReadLine (cancellationToken).TrimEnd ();\n\t\t\t\t\tpc.Status = Pop3Engine.GetCommandStatus (response, out text);\n\t\t\t\t\tpc.StatusText = text;\n\n\t\t\t\t\tif (pc.Status == Pop3CommandStatus.ProtocolError)\n\t\t\t\t\t\tthrow new Pop3ProtocolException (string.Format (\"Unexpected response from server: {0}\", response));\n\t\t\t\t}\n\n\t\t\t\tAuthMessage = text;\n\t\t\t}\n\n\t\t\tasync Task OnDataReceivedAsync (Pop3Engine pop3, Pop3Command pc, string text, CancellationToken cancellationToken)\n\t\t\t{\n\t\t\t\tpop3.CheckConnected ();\n\n\t\t\t\twhile (pc.Status == Pop3CommandStatus.Continue && !mechanism.IsAuthenticated) {\n\t\t\t\t\tvar challenge = await mechanism.ChallengeAsync (text, cancellationToken).ConfigureAwait (false);\n\t\t\t\t\tvar buf = Encoding.ASCII.GetBytes (challenge + \"\\r\\n\");\n\n\t\t\t\t\tawait pop3.Stream.WriteAsync (buf, 0, buf.Length, cancellationToken).ConfigureAwait (false);\n\t\t\t\t\tawait pop3.Stream.FlushAsync (cancellationToken).ConfigureAwait (false);\n\n\t\t\t\t\tvar response = (await pop3.ReadLineAsync (cancellationToken).ConfigureAwait (false)).TrimEnd ();\n\t\t\t\t\tpc.Status = Pop3Engine.GetCommandStatus (response, out text);","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Pop3/Pop3Client.cs#L678-L714","documentation":"During the synchronous AUTH-based data-received callback in Pop3Client, the server's response line was parsed by Pop3Engine.GetCommandStatus and classified as Pop3CommandStatus.ProtocolError, so MailKit throws Pop3ProtocolException with the raw response text embedded. This means the server sent something that is not a valid POP3 (+OK / -ERR style) status line at a point where one was required. It indicates a malformed or non-protocol-compliant server reply.","triggerScenarios":"Calling the synchronous authentication/data path (e.g. Authenticate or an AUTH command completing via OnDataReceived) where pop3.ReadLine returns a response that GetCommandStatus cannot map to a known Pop3CommandStatus — e.g. garbage bytes, an empty line, or a server greeting/response that is not +OK or -ERR.","commonSituations":"Connecting to a non-POP3 port (SMTP/IMAP server or a plain HTTP endpoint) that answers with HTML or SMTP syntax; a proxy/firewall or captive portal injecting a banner; a misbehaving or very old POP3 server emitting nonstandard replies; a server that responds to SASL challenges with unexpected text.","solutions":["Inspect the '{0}' text in the exception — it contains the exact offending response; confirm the endpoint really speaks POP3.","Verify the host/port combination (typically 110 for plain POP3, 995 for POP3S) and that no proxy is intercepting the connection.","Try connecting with SecureSocketOptions.None temporarily or against a known-good server to isolate whether the server is non-compliant.","Enable protocol logging (new ProtocolLogger(Console.Error)) to capture the full server conversation for the server vendor."],"exampleFix":"// before\nclient.Connect(\"mail.example.com\", 587, SecureSocketOptions.None); // port is SMTP, not POP3\n// after\nclient.Connect(\"mail.example.com\", 995, SecureSocketOptions.SslOnConnect);","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify the endpoint speaks POP3 before use\nusing (var probe = new TcpClient(host, port)) {\n    var greeting = ReadLine(probe.GetStream());\n    if (greeting == null || !greeting.StartsWith(\"+OK\"))\n        throw new InvalidOperationException($\"Not a POP3 server: {greeting}\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.Authenticate(user, pass, cancellationToken);\n} catch (Pop3ProtocolException ex) {\n    logger.LogError(ex, \"POP3 server sent a non-protocol response: {Response}\", ex.Message);\n    throw;\n}","preventionTips":["Confirm the host/port serves POP3 (110/995) before wiring configuration.","Log the server response text embedded in the exception to diagnose proxy injections.","Use protocol logging (ProtocolLogger) to capture full server conversations.","Avoid routing POP3 through HTTP proxies or captive networks in production."],"tags":["pop3","mailkit","protocol-error","network"],"backgroundTag":"unexpected-response-shape","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}