{"record":{"id":"378b5981fc2384d5","repo":"jstedfast/MailKit","slug":"the-imapclient-is-not-authenticated","errorCode":null,"errorMessage":"The ImapClient is not authenticated.","messagePattern":"The ImapClient is not authenticated\\.","errorType":"exception","errorClass":"ServiceNotAuthenticatedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapClient.cs","lineNumber":236,"sourceCode":"\t\t\tget { return engine.Rights; }\n\t\t}\n\n\t\tvoid CheckDisposed ()\n\t\t{\n\t\t\tif (disposed)\n\t\t\t\tthrow new ObjectDisposedException (nameof (ImapClient));\n\t\t}\n\n\t\tvoid CheckConnected ()\n\t\t{\n\t\t\tif (!IsConnected)\n\t\t\t\tthrow new ServiceNotConnectedException (\"The ImapClient 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 ImapClient is not authenticated.\");\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Instantiate a new <see cref=\"ImapFolder\"/>.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// <para>Creates a new <see cref=\"ImapFolder\"/> instance.</para>\n\t\t/// <note type=\"note\">This method's purpose is to allow subclassing <see cref=\"ImapFolder\"/>.</note>\n\t\t/// </remarks>\n\t\t/// <returns>The IMAP folder instance.</returns>\n\t\t/// <param name=\"args\">The constructor arguments.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"args\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tprotected virtual ImapFolder CreateImapFolder (ImapFolderConstructorArgs args)\n\t\t{\n\t\t\tvar folder = new ImapFolder (args);\n","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapClient.cs#L218-L254","documentation":"CheckAuthenticated guards IMAP commands that require a successful login: if IsAuthenticated is false, ImapClient throws ServiceNotAuthenticatedException. Connection alone is not enough — the session must be in the Authenticated state before most mailbox operations.","triggerScenarios":"Calling operations like NoOp, Notify, Enable(QuickResync/UTF8=ACCEPT), or IDLE after Connect but before Authenticate, after a failed AuthenticateAsync, or after the server reverts to pre-auth state following a disconnect/reconnect.","commonSituations":"Skipping the Authenticate step in setup code; credentials rejected (bad password, OAuth token expired) so authentication silently failed; reconnecting after a drop and re-issuing commands without re-authenticating.","solutions":["Call AuthenticateAsync (or Authenticate) after ConnectAsync and check IsAuthenticated before issuing commands","Verify authentication succeeded — inspect exceptions from AuthenticateAsync rather than swallowing them","On reconnect, re-run both Connect and Authenticate before resuming commands"],"exampleFix":"// before\nawait client.ConnectAsync(host, port, options);\nawait client.EnableQuickResyncAsync(); // not authenticated yet\n// after\nawait client.ConnectAsync(host, port, options);\nawait client.AuthenticateAsync(user, password);\nawait client.EnableQuickResyncAsync();","handlingStrategy":"validation","validationCode":"if (!client.IsAuthenticated)\n\tthrow new InvalidOperationException(\"Authenticate before issuing IMAP commands.\");","typeGuard":"bool CanRunCommands(IMapClient c) => c.IsConnected && c.IsAuthenticated;","tryCatchPattern":"try {\n\tawait client.EnableQuickResyncAsync();\n} catch (ServiceNotAuthenticatedException) {\n\tawait client.AuthenticateAsync(user, password);\n}","preventionTips":["Always follow ConnectAsync with AuthenticateAsync before any mailbox/extension calls","Handle AuthenticationException from AuthenticateAsync rather than ignoring it","After reconnects, re-authenticate before resuming commands"],"tags":["imap","authentication","state"],"backgroundTag":"client-not-authenticated","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"}