{"record":{"id":"71236b9d7294b35a","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-password","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'password')","messagePattern":"Value cannot be null\\. \\(Parameter 'password'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/MailService.cs","lineNumber":1273,"sourceCode":"\t\t/// <exception cref=\"MailKit.Security.SaslException\">\n\t\t/// A SASL authentication error occurred.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.IO.IOException\">\n\t\t/// An I/O error occurred.\n\t\t/// </exception>\n\t\t/// <exception cref=\"ProtocolException\">\n\t\t/// A protocol error occurred.\n\t\t/// </exception>\n\t\tpublic void Authenticate (Encoding encoding, string userName, string password, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tif (encoding == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (encoding));\n\n\t\t\tif (userName == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (userName));\n\n\t\t\tif (password == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (password));\n\n\t\t\tvar credentials = new NetworkCredential (userName, password);\n\n\t\t\tAuthenticate (encoding, credentials, cancellationToken);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Asynchronously authenticate using the specified user name and password.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// <para>Asynchronously authenticates using the supplied credentials.</para>\n\t\t/// <para>If the server supports one or more SASL authentication mechanisms, then\n\t\t/// the SASL mechanisms that both the client and server support (not including any\n\t\t/// OAUTH mechanisms) are tried in order of greatest security to weakest security.\n\t\t/// Once a SASL authentication mechanism is found that both client and server support,\n\t\t/// the credentials are used to authenticate.</para>\n\t\t/// <para>If the server does not support SASL or if no common SASL mechanisms\n\t\t/// can be found, then the default login command is used as a fallback.</para>","sourceCodeStart":1255,"sourceCodeEnd":1291,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MailService.cs#L1255-L1291","documentation":"Authenticate requires a non-null password; MailKit wraps userName/password into a NetworkCredential for SASL authentication, and a null password is rejected with ArgumentNullException naming parameter 'password'.","triggerScenarios":"Calling Authenticate(encoding, userName, null) — password is null.","commonSituations":"Secret not found in user-secrets/environment/Key Vault, config key typo, or secrets not injected into the container/deployment.","solutions":["Provide the password, preferably from a secret store, e.g. Authenticate(Encoding.UTF8, user, secret)","Fix the secret configuration so the value is actually present at runtime","Guard against null and surface a 'SMTP password not configured' error before calling"],"exampleFix":"// before\nclient.Authenticate(Encoding.UTF8, user, Environment.GetEnvironmentVariable(\"SMTP_PASS\")); // null if unset\n// after\nvar pass = Environment.GetEnvironmentVariable(\"SMTP_PASS\") ?? throw new InvalidOperationException(\"SMTP_PASS not set\");\nclient.Authenticate(Encoding.UTF8, user, pass);","handlingStrategy":"validation","validationCode":"var pass = Environment.GetEnvironmentVariable(\"SMTP_PASS\");\nif (string.IsNullOrEmpty(pass))\n    throw new InvalidOperationException(\"SMTP password not configured\");\nclient.Authenticate(Encoding.UTF8, userName, pass);","typeGuard":"static bool HasPassword(string password) => !string.IsNullOrEmpty(password);","tryCatchPattern":"try { client.Authenticate(Encoding.UTF8, userName, password); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"password\") { throw new ConfigurationException(\"Mail password is not configured (check secret store)\", ex); }","preventionTips":["Store passwords in user-secrets/Key Vault and verify injection per environment","Fail at startup with a credential presence check instead of at first send","Never construct credentials from raw config lookups without null checks"],"tags":["mailkit","argumentnullexception","credentials","secrets","authentication"],"backgroundTag":"missing-credentials","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"}