{"record":{"id":"8639d1394d54bb68","repo":"jstedfast/MailKit","slug":"the-pop3client-is-not-connected","errorCode":null,"errorMessage":"The Pop3Client is not connected.","messagePattern":"The Pop3Client is not connected\\.","errorType":"exception","errorClass":"ServiceNotConnectedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Pop3/Pop3Client.cs","lineNumber":250,"sourceCode":"\t\t\tget {\n\t\t\t\tCheckDisposed ();\n\t\t\t\tCheckConnected ();\n\t\t\t\tCheckAuthenticated ();\n\n\t\t\t\treturn octets;\n\t\t\t}\n\t\t}\n\n\t\tvoid CheckDisposed ()\n\t\t{\n\t\t\tif (disposed)\n\t\t\t\tthrow new ObjectDisposedException (nameof (Pop3Client));\n\t\t}\n\n\t\tvoid CheckConnected ()\n\t\t{\n\t\t\tif (!IsConnected)\n\t\t\t\tthrow new ServiceNotConnectedException (\"The Pop3Client is not connected.\");\n\t\t}\n\n\t\tvoid CheckAuthenticated ()\n\t\t{\n\t\t\tif (!IsAuthenticated)\n\t\t\t\tthrow new ServiceNotAuthenticatedException (\"The Pop3Client has not been authenticated.\");\n\t\t}\n\n\t\tbool ValidateRemoteCertificate (object? sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors)\n\t\t{\n\t\t\tvar host = engine.Uri!.Host;\n\t\t\tbool valid;\n\n\t\t\tsslValidationInfo?.Dispose ();\n\t\t\tsslValidationInfo = null;\n\n\t\t\tif (ServerCertificateValidationCallback != null) {\n\t\t\t\tvalid = ServerCertificateValidationCallback (host, certificate, chain, sslPolicyErrors);","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Pop3/Pop3Client.cs#L232-L268","documentation":"Pop3Client.CheckConnected is the guard invoked before nearly every network operation (GetMessageCount, Size, NoOp, language commands, etc.); it throws ServiceNotConnectedException when IsConnected is false. It means the client has never connected, or the connection was dropped/closed before the call.","triggerScenarios":"Calling any Pop3Client operation before ConnectAsync, after DisconnectAsync, after a timeout/protocol exception disconnected the client, or after the server dropped the connection.","commonSituations":"Reusing a client instance across a previous failed session; forgetting Connect in a code path; a prior TimeoutException/ImapProtocolException-style disconnect left the client dead and subsequent calls fail; wrong assumption that a client stays connected between application requests.","solutions":["Check client.IsConnected before operations and call ConnectAsync/AuthenticateAsync when false.","Wrap operations in a reconnect helper: catch ServiceNotConnectedException, reconnect, retry once.","Don't reuse stale client instances across long gaps; create and connect a fresh Pop3Client per unit of work (POP3 sessions are short-lived by design)."],"exampleFix":"// before\nusing var client = new Pop3Client();\nawait client.ConnectAsync(host, 995, true);\n// ... later, connection dropped ...\nint count = await client.GetMessageCountAsync(); // throws\n\n// after\nusing var client = new Pop3Client();\nasync Task EnsureConnectedAsync()\n{\n    if (!client.IsConnected)\n    {\n        await client.ConnectAsync(host, 995, true);\n        await client.AuthenticateAsync(user, pass);\n    }\n}\nawait EnsureConnectedAsync();\nint count = await client.GetMessageCountAsync();","handlingStrategy":"try-catch","validationCode":"if (client == null || !client.IsConnected)\n    throw new InvalidOperationException(\"Pop3Client must be connected before use\");","typeGuard":null,"tryCatchPattern":"try { await client.GetMessageCountAsync(); }\ncatch (ServiceNotConnectedException) {\n    await client.ConnectAsync(host, 995, true);\n    await client.AuthenticateAsync(user, pass);\n    await client.GetMessageCountAsync();\n}","preventionTips":["Check IsConnected before every operation or use a EnsureConnected helper","Reconnect after any exception — MailKit disconnects the client on timeouts and protocol errors","Create fresh Pop3Client sessions per unit of work; POP3 is not designed for long-lived connections"],"tags":["pop3","connection-state","not-connected","mailkit"],"backgroundTag":"invalid-state-transition","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}