jstedfast/MailKit · error · InvalidOperationException

The UTF8 extension has not been enabled.

Error message

The UTF8 extension has not been enabled.

What it means

After capability checks pass, CreateAppendOptions verifies Engine.UTF8Enabled. A server may support UTF8 (capability present, so format.International stays true) but the client never issued ENABLE UTF8, so the extension is not active on the connection; Append then fails with InvalidOperationException.

Solutions

  1. Call imapClient.EnableUTF8() after authentication and before Append when using International options.
  2. Check client.UTF8Enabled before appending and enable or downgrade options accordingly.
  3. If the server is UTF8Only, you must enable UTF8 — there is no non-UTF8 path.
  4. Re-run EnableUTF8 on every new/reconnected session.

Example fix

// before
client.Connect (...); client.Authenticate (...);
folder.Append (internationalOptions, request);
// after
client.Connect (...); client.Authenticate (...);
if ((client.Capabilities & ImapCapabilities.UTF8Accept) != 0)
    client.EnableUTF8 ();
folder.Append (internationalOptions, request);
Defensive patterns

Strategy: validation

Validate before calling

if (options.International && !client.UTF8Enabled && (client.Capabilities & ImapCapabilities.UTF8Accept) != 0) client.EnableUTF8 ();

Type guard

bool Utf8Ready (ImapClient c) => c.UTF8Enabled || (c.Capabilities & ImapCapabilities.UTF8Accept) == 0;

Try / catch

try { folder.Append (options, request); } catch (InvalidOperationException ex) when (ex.Message.Contains ("UTF8")) { client.EnableUTF8 (); folder.Append (options, request); }

Prevention

When it happens

Trigger: Calling Append/AppendAsync with an International FormatOptions (or server is UTF8=ONLY) when ImapClient.EnableUTF8() was never called for the current connection.

Common situations: Reconnecting after a dropped connection without re-issuing EnableUTF8 (capabilities/enabled state resets per session); upgrading a server to UTF8=ONLY while client code still assumes default behavior; forgetting EnableUTF8 after adding internationalization support.

Related errors


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

Appendix: source

Thrown at MailKit/Net/Imap/ImapFolder.cs:4410

				ProcessExpungeResponse (ic);
			}
		}

		FormatOptions CreateAppendOptions (FormatOptions options)
		{
			if (options.International && (Engine.Capabilities & ImapCapabilities.UTF8Accept) == 0)
				throw new NotSupportedException ("The IMAP server does not support the UTF8 extension.");

			var format = options.Clone ();
			format.NewLineFormat = NewLineFormat.Dos;
			format.EnsureNewLine = true;

			if ((Engine.Capabilities & ImapCapabilities.UTF8Only) == ImapCapabilities.UTF8Only)
				format.International = true;

			if (format.International && !Engine.UTF8Enabled)
				throw new InvalidOperationException ("The UTF8 extension has not been enabled.");

			return format;
		}

		ImapCommand QueueAppendCommand (FormatOptions options, IAppendRequest request, CancellationToken cancellationToken)
		{
			if (options == null)
				throw new ArgumentNullException (nameof (options));

			if (request == null)
				throw new ArgumentNullException (nameof (request));

			CheckState (false, false);

			var format = CreateAppendOptions (options);

			if (request.Annotations != null && request.Annotations.Count > 0 && (Engine.Capabilities & ImapCapabilities.Annotate) == 0)
				throw new NotSupportedException ("The IMAP server does not support annotations.");

View on GitHub (pinned to 9d3859a785)