{"record":{"id":"e755421e1807844f","repo":"jstedfast/MailKit","slug":"the-pop3client-has-not-been-authenticated","errorCode":null,"errorMessage":"The Pop3Client has not been authenticated.","messagePattern":"The Pop3Client has not been authenticated\\.","errorType":"exception","errorClass":"ServiceNotAuthenticatedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Pop3/Pop3Client.cs","lineNumber":256,"sourceCode":"\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);\n#if NETFRAMEWORK\n\t\t\t} else if (ServicePointManager.ServerCertificateValidationCallback != null) {\n\t\t\t\tvalid = ServicePointManager.ServerCertificateValidationCallback (host, certificate, chain, sslPolicyErrors);\n#endif\n\t\t\t} else {\n\t\t\t\tvalid = DefaultServerCertificateValidationCallback (host, certificate, chain, sslPolicyErrors);","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Pop3/Pop3Client.cs#L238-L274","documentation":"MailKit throws ServiceNotAuthenticatedException from Pop3Client.CheckAuthenticated() whenever a POP3 command that requires a logged-in session is issued while IsAuthenticated is false. The client may be connected, but the AUTH/USER-PASS handshake has not completed (or the session was dropped and reconnected without re-authenticating). It is a state precondition guard protecting commands like GetMessageCount, Size, NoOp, Count, and SupportsUids that the POP3 server only serves after authentication.","triggerScenarios":"Calling any of Count, GetMessageCount, Size, NoOp, SupportsUids, or QueueUidlCommand on a Pop3Client that is connected but on which Authenticate() was never called; or after a reconnect where authentication was not redone.","commonSituations":"Forgetting to call Authenticate after Connect before enumerating messages; credentials supplied only to Connect (POP3 needs explicit Authenticate); an SSL/TLS or network hiccup caused MailKit to reconnect, resetting the authenticated state; sharing a Pop3Client across threads where another thread disconnected; using SASL mechanisms not advertised by the server so authentication silently failed.","solutions":["Call client.Authenticate(username, password, cancellationToken) after Connect and before any message commands.","Check client.IsAuthenticated before issuing mailbox commands, and authenticate if false.","If using auto-connect/reconnect logic, re-run both Connect and Authenticate after every reconnection.","Verify the server actually advertises a SASL mechanism you support (check client.AuthenticationMechanisms); supply a matching SaslMechanism or fall back to user/password."],"exampleFix":"// before\nclient.Connect(\"pop.example.com\", 995, SecureSocketOptions.SslOnConnect);\nint count = client.Count; // throws ServiceNotAuthenticatedException\n// after\nclient.Connect(\"pop.example.com\", 995, SecureSocketOptions.SslOnConnect);\nclient.Authenticate(\"user\", \"pass\", cancellationToken);\nint count = client.Count;","handlingStrategy":"try-catch","validationCode":"if (!client.IsConnected)\n    client.Connect(host, port, SecureSocketOptions.SslOnConnect);\nif (!client.IsAuthenticated)\n    client.Authenticate(user, pass, cancellationToken);","typeGuard":null,"tryCatchPattern":"try {\n    int count = client.Count;\n} catch (ServiceNotAuthenticatedException) {\n    client.Authenticate(user, pass, cancellationToken);\n    int count = client.Count;\n}","preventionTips":["Always pair Connect with Authenticate in a single helper method before any mailbox operations.","Check IsAuthenticated before message commands, especially after reconnects.","Re-authenticate after any network error recovery path.","Enable protocol logging during development to confirm the AUTH handshake completed."],"tags":["pop3","mailkit","authentication","state-error"],"backgroundTag":"authentication-required","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"}