jstedfast/MailKit · error · ArgumentException

The address cannot be empty.

Error message

The address cannot be empty.

What it means

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.

Solutions

  1. Check that the address is non-empty (and ideally well-formed) before calling Verify
  2. Use StringSplitOptions.RemoveEmptyEntries when splitting address lists
  3. Return a validation error to the caller for empty addresses instead of hitting the SMTP server

Example fix

// before
await smtpClient.VerifyAsync(email.Trim());
// after
var addr = email?.Trim();
if (string.IsNullOrEmpty(addr))
    throw new ArgumentException("Address is required", nameof(email));
await smtpClient.VerifyAsync(addr);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(address))
    throw new ArgumentException("Address must not be empty", nameof(address));
await smtpClient.VerifyAsync(address);

Type guard

bool IsValidAddress(string a) => !string.IsNullOrWhiteSpace(a);

Try / catch

try {
    var result = await smtpClient.VerifyAsync(address);
} catch (ArgumentException) {
    logger.LogWarning("VRFY called with empty address");
}

Prevention

When it happens

Trigger: Calling Verify/VerifyAsync with "" — commonly a trimmed input that was empty or an empty element from a split address list.

Common situations: Blank email field in a form submitted to an address-verification job; Split producing empty entries; config key set to an empty string.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/48f9c4a962a5168a. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Net/Smtp/SmtpClient.cs:2762

		/// The SMTP command failed.
		/// </exception>
		/// <exception cref="SmtpProtocolException">
		/// An SMTP protocol exception occurred.
		/// </exception>
		public InternetAddressList Expand (string alias, CancellationToken cancellationToken = default)
		{
			var response = SendCommandInternal (CreateExpandCommand (alias), cancellationToken);

			return ParseExpandResponse (response);
		}

		string CreateVerifyCommand (string address)
		{
			if (address == null)
				throw new ArgumentNullException (nameof (address));

			if (address.Length == 0)
				throw new ArgumentException ("The address cannot be empty.", nameof (address));

			if (address.IndexOfAny (NewLineCharacters) != -1)
				throw new ArgumentException ("The address cannot contain newline characters.", nameof (address));

			CheckDisposed ();

			if (!IsConnected)
				throw new ServiceNotConnectedException ("The SmtpClient is not connected.");

			return string.Format ("VRFY {0}\r\n", address);
		}

		static MailboxAddress ParseVerifyResponse (SmtpResponse response)
		{
			if (response.StatusCode == SmtpStatusCode.Ok)
				return MailboxAddress.Parse (response.Response);

			throw new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);

View on GitHub (pinned to 9d3859a785)