{"record":{"id":"b5e04e2fad395a8c","repo":"jstedfast/MailKit","slug":"no-compatible-authentication-mechanisms-found-smtpclient","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/SmtpClient.cs","lineNumber":1277,"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\tinternal static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOptions options, out Uri uri, out bool starttls)\n\t\t{\n\t\t\tswitch (options) {\n\t\t\tdefault:\n\t\t\t\tif (port == 0)\n\t\t\t\t\tport = 25;\n\t\t\t\tbreak;\n\t\t\tcase SecureSocketOptions.Auto:\n\t\t\t\tswitch (port) {\n\t\t\t\tcase 0: port = 25; goto default;\n\t\t\t\tcase 465: options = SecureSocketOptions.SslOnConnect; break;\n\t\t\t\tdefault: options = SecureSocketOptions.StartTlsWhenAvailable; break;","sourceCodeStart":1259,"sourceCodeEnd":1295,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/SmtpClient.cs#L1259-L1295","documentation":"During the AUTH handshake MailKit iterates its enabled SaslAuthenticationMechanisms filtered against the mechanisms the server advertised; if every enabled mechanism was rejected or none overlap with the server's list, no attempt succeeded and 'tried' stays false, so it throws NotSupportedException(\"No compatible authentication mechanisms found.\").","triggerScenarios":"Server advertises only AUTH mechanisms that are disabled in client.AuthenticationMechanisms (or vice versa), e.g. server offers only CRAM-SHA256/GSSAPI while the client enables only PLAIN/LOGIN, or the developer removed mechanisms from client.AuthenticationMechanisms.","commonSituations":"Hardened SMTP servers disabling PLAIN/LOGIN over unencrypted links; Windows environments expecting GSSAPI/NTLM support MailKit doesn't ship; custom mechanism lists configured for a different server.","solutions":["Inspect client.AuthenticationMechanisms after Connect and enable (add back) the mechanisms the server supports.","Use a TLS-protected connection (STARTTLS/SSL) so the server will advertise PLAIN/LOGIN.","Pass an explicit SaslMechanism (e.g. new SaslMechanismLogin(user, pass) or SaslMechanismNtlm) that matches a server-advertised mechanism.","If the server only offers unsupported mechanisms (GSSAPI/Kerberos), configure the server or use an alternate auth path (e.g. OAuth2 via SaslMechanismOAuth2)."],"exampleFix":"// before\nvar client = new SmtpClient();\nclient.AuthenticationMechanisms.Clear(); // no mechanisms left\nclient.Connect(host, 587, SecureSocketOptions.StartTls);\nclient.Authenticate(user, pass); // NotSupportedException\n\n// after\nvar client = new SmtpClient(new ProtocolLogger(Console.OpenStandardError()));\nclient.Connect(host, 587, SecureSocketOptions.StartTls);\nforeach (var mech in client.AuthenticationMechanisms)\n    Console.WriteLine(mech); // verify overlap with server list\nclient.Authenticate(user, pass);","handlingStrategy":"validation","validationCode":"var supported = client.AuthenticationMechanisms;\nif (supported.Count == 0)\n    throw new InvalidOperationException(\"Server advertised no AUTH mechanisms.\");","typeGuard":null,"tryCatchPattern":"try {\n    client.Authenticate(user, pass);\n} catch (NotSupportedException ex) {\n    // log client.AuthenticationMechanisms and adjust enabled mechanisms\n    throw new MailAuthConfigurationException(\"No overlapping SASL mechanisms\", ex);\n}","preventionTips":["Do not remove entries from client.AuthenticationMechanisms without a reason.","Log advertised mechanisms after connect when debugging auth.","Use TLS so PLAIN/LOGIN are offered by the server.","For exotic servers, supply an explicit SaslMechanism matching the server list."],"tags":["smtp","mailkit","sasl","mechanism-negotiation"],"backgroundTag":"unsupported-operation","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"}