{"record":{"id":"48f9c4a962a5168a","repo":"jstedfast/MailKit","slug":"the-address-cannot-be-empty","errorCode":null,"errorMessage":"The address cannot be empty.","messagePattern":"The address cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Smtp/SmtpClient.cs","lineNumber":2762,"sourceCode":"\t\t/// The SMTP command failed.\n\t\t/// </exception>\n\t\t/// <exception cref=\"SmtpProtocolException\">\n\t\t/// An SMTP protocol exception occurred.\n\t\t/// </exception>\n\t\tpublic InternetAddressList Expand (string alias, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tvar response = SendCommandInternal (CreateExpandCommand (alias), cancellationToken);\n\n\t\t\treturn ParseExpandResponse (response);\n\t\t}\n\n\t\tstring CreateVerifyCommand (string address)\n\t\t{\n\t\t\tif (address == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (address));\n\n\t\t\tif (address.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"The address cannot be empty.\", nameof (address));\n\n\t\t\tif (address.IndexOfAny (NewLineCharacters) != -1)\n\t\t\t\tthrow new ArgumentException (\"The address cannot contain newline characters.\", nameof (address));\n\n\t\t\tCheckDisposed ();\n\n\t\t\tif (!IsConnected)\n\t\t\t\tthrow new ServiceNotConnectedException (\"The SmtpClient is not connected.\");\n\n\t\t\treturn string.Format (\"VRFY {0}\\r\\n\", address);\n\t\t}\n\n\t\tstatic MailboxAddress ParseVerifyResponse (SmtpResponse response)\n\t\t{\n\t\t\tif (response.StatusCode == SmtpStatusCode.Ok)\n\t\t\t\treturn MailboxAddress.Parse (response.Response);\n\n\t\t\tthrow new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);","sourceCodeStart":2744,"sourceCodeEnd":2780,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Smtp/SmtpClient.cs#L2744-L2780","documentation":"SmtpClient.Verify/CreateVerifyCommand throws ArgumentException when the address is the empty string. An empty VRFY argument yields an invalid SMTP command and no server can verify it, so it is rejected before the command is sent.","triggerScenarios":"Calling Verify/VerifyAsync with \"\" — commonly a trimmed input that was empty or an empty element from a split address list.","commonSituations":"Blank email field in a form submitted to an address-verification job; Split producing empty entries; config key set to an empty string.","solutions":["Check that the address is non-empty (and ideally well-formed) before calling Verify","Use StringSplitOptions.RemoveEmptyEntries when splitting address lists","Return a validation error to the caller for empty addresses instead of hitting the SMTP server"],"exampleFix":"// before\nawait smtpClient.VerifyAsync(email.Trim());\n// after\nvar addr = email?.Trim();\nif (string.IsNullOrEmpty(addr))\n    throw new ArgumentException(\"Address is required\", nameof(email));\nawait smtpClient.VerifyAsync(addr);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(address))\n    throw new ArgumentException(\"Address must not be empty\", nameof(address));\nawait smtpClient.VerifyAsync(address);","typeGuard":"bool IsValidAddress(string a) => !string.IsNullOrWhiteSpace(a);","tryCatchPattern":"try {\n    var result = await smtpClient.VerifyAsync(address);\n} catch (ArgumentException) {\n    logger.LogWarning(\"VRFY called with empty address\");\n}","preventionTips":["Trim and validate email inputs before use","Use RemoveEmptyEntries when splitting address lists","Short-circuit empty inputs with a validation response"],"tags":["smtp","validation","mailkit"],"backgroundTag":"empty-required-field","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}