{"record":{"id":"a3b8f35bceffa24f","repo":"jstedfast/MailKit","slug":"no-compatible-authentication-mechanisms-found","errorCode":null,"errorMessage":"No compatible authentication mechanisms found.","messagePattern":"No compatible authentication mechanisms found\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Smtp/AsyncSmtpClient.cs","lineNumber":415,"sourceCode":"\t\t\t\t\t\tOnAuthenticated (response.Response);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tvar message = string.Format (CultureInfo.InvariantCulture, \"{0}: {1}\", (int) response.StatusCode, response.Response);\n\t\t\t\t\tException inner;\n\n\t\t\t\t\tif (saslException != null)\n\t\t\t\t\t\tinner = new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response, saslException);\n\t\t\t\t\telse\n\t\t\t\t\t\tinner = new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);\n\n\t\t\t\t\tauthException = new AuthenticationException (message, inner);\n\t\t\t\t}\n\n\t\t\t\tif (tried)\n\t\t\t\t\tthrow authException ?? new AuthenticationException ();\n\n\t\t\t\tthrow new NotSupportedException (\"No compatible authentication mechanisms found.\");\n\t\t\t} catch (Exception ex) {\n\t\t\t\toperation.SetError (ex);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t}\n\n\t\tasync Task SslHandshakeAsync (SslStream ssl, string host, CancellationToken cancellationToken)\n\t\t{\n#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER\n\t\t\tawait ssl.AuthenticateAsClientAsync (GetSslClientAuthenticationOptions (host, ValidateRemoteCertificate), cancellationToken).ConfigureAwait (false);\n#else\n\t\t\tawait ssl.AuthenticateAsClientAsync (host, ClientCertificates, SslProtocols, CheckCertificateRevocation).ConfigureAwait (false);\n#endif\n\t\t}\n\n\t\tasync Task PostConnectAsync (Stream stream, string host, int port, SecureSocketOptions options, bool starttls, CancellationToken cancellationToken)\n\t\t{\n\t\t\tclientConnectedTimestamp = Stopwatch.GetTimestamp ();","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/AsyncSmtpClient.cs#L397-L433","documentation":"AsyncSmtpClient.AuthenticateAsync tries each SASL mechanism the server advertised and that the client supports. If nothing was tried at all - because the server advertised no mechanisms that intersect with MailKit's supported set and no fallback was possible - it throws NotSupportedException with this message.","triggerScenarios":"Calling AuthenticateAsync against a server whose EHLO response lists no AUTH mechanisms (or only mechanisms MailKit lacks, and its preferred fallback mechanism is not in the server's list).","commonSituations":"Connecting to an SMTP relay that requires pre-authentication by IP (no AUTH advertised); servers offering only exotic mechanisms; server misconfigured without an AUTH mechanism plugin.","solutions":["Check SmtpClient.AuthenticationMechanisms after connecting to see what the server offers.","Remove the client-side mechanism restriction (the useAuthMechanisms/Capabilities filter) so MailKit may use a mechanism the server actually advertises.","Fix the server configuration to advertise a standard mechanism (PLAIN, LOGIN, CRAM-MD5, XOAUTH2).","If no AUTH is offered because the server auto-trusts your IP, skip calling AuthenticateAsync."],"exampleFix":"// before\nclient.Authenticated += ...; await client.AuthenticateAsync(user, pass); // server advertises only GSSAPI\n// after\nif (client.AuthenticationMechanisms.Contains(\"PLAIN\"))\n    await client.AuthenticateAsync(user, pass);\nelse\n    throw new Exception($\"No usable auth mechanism; server offers: {string.Join(\",\", client.AuthenticationMechanisms)}\");","handlingStrategy":"validation","validationCode":"await client.ConnectAsync(host, port, options);\nvar supported = client.AuthenticationMechanisms;\nif (supported.Count == 0)\n    throw new InvalidOperationException(\"Server advertises no AUTH mechanisms; cannot authenticate\");\nvar usable = supported.Intersect(new[] { \"PLAIN\", \"LOGIN\", \"CRAM-MD5\", \"XOAUTH2\", \"NTLM\", \"DIGEST-MD5\" }).ToList();\nif (usable.Count == 0)\n    throw new InvalidOperationException($\"No mutually supported SASL mechanism. Server offers: {string.Join(\", \", supported)}\");","typeGuard":"bool CanAuthenticate(SmtpClient c) => c.IsConnected && c.AuthenticationMechanisms.Count > 0;","tryCatchPattern":"try {\n    await client.AuthenticateAsync(user, token);\n} catch (NotSupportedException ex) {\n    throw new ApplicationException($\"No compatible SASL mechanism; server offers: {string.Join(\",\", client.AuthenticationMechanisms)}\", ex);\n} catch (AuthenticationException ex) {\n    // credentials wrong - different problem, handle separately\n    throw;\n}","preventionTips":["Inspect AuthenticationMechanisms after connect before authenticating","Do not restrict MailKit's allowed mechanisms unless you know the server's list","Configure the server to advertise PLAIN or LOGIN over TLS as a baseline","If the server auto-trusts your IP, skip AuthenticateAsync entirely"],"tags":["smtp","authentication","sasl","async"],"backgroundTag":"no-compatible-auth-mechanism","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"}