{"record":{"id":"10d81f255d6b395e","repo":"jstedfast/MailKit","slug":"unexpected-greeting-from-server-0","errorCode":null,"errorMessage":"Unexpected greeting from server: {0}","messagePattern":"Unexpected greeting from server: (.+?)","errorType":"exception","errorClass":"Pop3ProtocolException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Pop3/Pop3Engine.cs","lineNumber":258,"sourceCode":"\t\t\t\ttoken = greeting.Substring (0, index);\n\n\t\t\t\twhile (index < greeting.Length && char.IsWhiteSpace (greeting[index]))\n\t\t\t\t\tindex++;\n\n\t\t\t\tif (index < greeting.Length)\n\t\t\t\t\ttext = greeting.Substring (index);\n\t\t\t\telse\n\t\t\t\t\ttext = string.Empty;\n\t\t\t} else {\n\t\t\t\ttext = string.Empty;\n\t\t\t\ttoken = greeting;\n\t\t\t}\n\n\t\t\tif (token != \"+OK\") {\n\t\t\t\tStream!.Dispose ();\n\t\t\t\tStream = null;\n\n\t\t\t\tthrow new Pop3ProtocolException (string.Format (\"Unexpected greeting from server: {0}\", greeting));\n\t\t\t}\n\n\t\t\tindex = text.IndexOf ('<');\n\t\t\tif (index != -1 && index + 1 < text.Length) {\n\t\t\t\tint endIndex = text.IndexOf ('>', index + 1);\n\n\t\t\t\tif (endIndex++ != -1) {\n\t\t\t\t\tApopToken = text.Substring (index, endIndex - index);\n\t\t\t\t\tCapabilities |= Pop3Capabilities.Apop;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tState = Pop3EngineState.Connected;\n\t\t}\n\n\t\tpublic NetworkOperation StartNetworkOperation (NetworkOperationKind kind, Uri? uri = null)\n\t\t{\n#if NET6_0_OR_GREATER","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Pop3/Pop3Engine.cs#L240-L276","documentation":"During connection, Pop3Engine.ParseGreeting reads the server's first line and requires it to start with '+OK'. If the server answers with anything else (-ERR, HTML, an SMTP banner, a captcha/abuse notice), the stream is disposed and a Pop3ProtocolException is thrown. It means the endpoint is not speaking POP3 as expected.","triggerScenarios":"Connecting Pop3Client.Connect/ConnectAsync to a port or host that is not a POP3 server (wrong port, HTTPS/IMAP/SMTP port), or when the server rejects the connection at greeting time (-ERR with a message such as 'Too many connections' or a service outage banner).","commonSituations":"Misconfigured port (e.g. 993 IMAP or 443 instead of 995 POP3S); firewalls/proxies returning an HTML error page; provider blocking your IP after failed logins; server temporarily in maintenance mode replying -ERR.","solutions":["Verify host/port and security (SecureSocketOptions) match a POP3 endpoint — typically 995 SSL/TLS or 110 STARTTLS/plain.","Log or capture the actual greeting text (it is embedded in the exception message) to see the server's -ERR reason.","Confirm the server speaks POP3: test with `openssl s_client -connect host:995 -quiet` and look for '+OK'.","If the greeting mentions connection limits or blocks, reduce connection frequency or contact the provider.","Retry with backoff only if the -ERR indicates a transient server condition."],"exampleFix":"// before\nclient.Connect(\"mail.example.com\", 443, SecureSocketOptions.SslOnConnect); // wrong port -> HTML greeting\n// after\nclient.Connect(\"mail.example.com\", 995, SecureSocketOptions.SslOnConnect); // POP3S","handlingStrategy":"try-catch","validationCode":"// before connecting, verify the endpoint speaks POP3 (manual check)\n// openssl s_client -connect host:995 -quiet  -> expect \"+OK ...\"","typeGuard":null,"tryCatchPattern":"try {\n    client.Connect(uri, SecureSocketOptions.SslOnConnect);\n} catch (Pop3ProtocolException ex) when (ex.Message.StartsWith(\"Unexpected greeting\")) {\n    logger.LogError(ex, \"Not a POP3 endpoint; check host/port/security settings\");\n}","preventionTips":["Double-check host, port and SSL mode against the provider's POP3 settings","Log the full exception message — it contains the server's actual greeting","Never reuse IMAP/SMTP connection settings for POP3"],"tags":["pop3","protocol-error","connection","greeting","mailkit"],"backgroundTag":"unexpected-api-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"}