jstedfast/MailKit · error · Pop3ProtocolException

Unexpected greeting from server

Error message

Unexpected greeting from server: {0}

What it means

During connection, Pop3Engine.ParseGreeting reads the server's first line and requires it to start with '+OK'. If the server answers with anything else (-ERR, HTML, an SMTP banner, a captcha/abuse notice), the stream is disposed and a Pop3ProtocolException is thrown. It means the endpoint is not speaking POP3 as expected.

Solutions

  1. Verify host/port and security (SecureSocketOptions) match a POP3 endpoint — typically 995 SSL/TLS or 110 STARTTLS/plain.
  2. Log or capture the actual greeting text (it is embedded in the exception message) to see the server's -ERR reason.
  3. Confirm the server speaks POP3: test with `openssl s_client -connect host:995 -quiet` and look for '+OK'.
  4. If the greeting mentions connection limits or blocks, reduce connection frequency or contact the provider.
  5. Retry with backoff only if the -ERR indicates a transient server condition.

Example fix

// before
client.Connect("mail.example.com", 443, SecureSocketOptions.SslOnConnect); // wrong port -> HTML greeting
// after
client.Connect("mail.example.com", 995, SecureSocketOptions.SslOnConnect); // POP3S
Defensive patterns

Strategy: try-catch

Validate before calling

// before connecting, verify the endpoint speaks POP3 (manual check)
// openssl s_client -connect host:995 -quiet  -> expect "+OK ..."

Try / catch

try {
    client.Connect(uri, SecureSocketOptions.SslOnConnect);
} catch (Pop3ProtocolException ex) when (ex.Message.StartsWith("Unexpected greeting")) {
    logger.LogError(ex, "Not a POP3 endpoint; check host/port/security settings");
}

Prevention

When it happens

Trigger: Connecting Pop3Client.Connect/ConnectAsync to a port or host that is not a POP3 server (wrong port, HTTPS/IMAP/SMTP port), or when the server rejects the connection at greeting time (-ERR with a message such as 'Too many connections' or a service outage banner).

Common situations: Misconfigured port (e.g. 993 IMAP or 443 instead of 995 POP3S); firewalls/proxies returning an HTML error page; provider blocking your IP after failed logins; server temporarily in maintenance mode replying -ERR.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at MailKit/Net/Pop3/Pop3Engine.cs:258

				token = greeting.Substring (0, index);

				while (index < greeting.Length && char.IsWhiteSpace (greeting[index]))
					index++;

				if (index < greeting.Length)
					text = greeting.Substring (index);
				else
					text = string.Empty;
			} else {
				text = string.Empty;
				token = greeting;
			}

			if (token != "+OK") {
				Stream!.Dispose ();
				Stream = null;

				throw new Pop3ProtocolException (string.Format ("Unexpected greeting from server: {0}", greeting));
			}

			index = text.IndexOf ('<');
			if (index != -1 && index + 1 < text.Length) {
				int endIndex = text.IndexOf ('>', index + 1);

				if (endIndex++ != -1) {
					ApopToken = text.Substring (index, endIndex - index);
					Capabilities |= Pop3Capabilities.Apop;
				}
			}

			State = Pop3EngineState.Connected;
		}

		public NetworkOperation StartNetworkOperation (NetworkOperationKind kind, Uri? uri = null)
		{
#if NET6_0_OR_GREATER

View on GitHub (pinned to 9d3859a785)