jstedfast/MailKit · error · NotSupportedException

The IMAP server does not support the Google Mail extensions.

Error message

The IMAP server does not support the Google Mail extensions.

What it means

QueueStoreCommands throws NotSupportedException when a Google-specific store operation (e.g. adding/removing Gmail X-GM-LABELS) is requested but the connected server does not advertise the Gmail extensions capability (ImapCapabilities.GMailExt1). Label changes require the X-GM-EXT-1 extension; MailKit refuses to send an unsupported command to a non-Gmail server.

Solutions

  1. Use standard IMAP flags instead: Store with MessageFlags (or custom flags if the server supports KEYWORDS).
  2. Branch on capability: call label APIs only when (client.Capabilities & ImapCapabilities.GMailExt1) != 0, otherwise use flags or app-level metadata.
  3. Connect to the actual Gmail endpoint (imap.gmail.com) so X-GM-EXT-1 is advertised; avoid capability-stripping proxies.
  4. If Gmail-specific semantics are essential, use the Gmail REST API instead of IMAP.

Example fix

// before
folder.AddLabels(uids, new [] { "Important" }); // throws on non-Gmail server
// after
if ((client.Capabilities & ImapCapabilities.GMailExt1) != 0) {
    folder.AddLabels(uids, new [] { "Important" });
} else {
    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));
}
Defensive patterns

Strategy: fallback

Validate before calling

bool gmailExt = (client.Capabilities & ImapCapabilities.GMailExt1) != 0;
if (gmailExt) {
    folder.AddLabels(uids, labels);
} else {
    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));
}

Try / catch

try {
    folder.AddLabels(uids, labels);
} catch (NotSupportedException) {
    // non-Gmail server: fall back to standard flags or app-side metadata
    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));
}

Prevention

When it happens

Trigger: Calling ImapFolder.AddLabels / RemoveLabels / SetLabels (or Store with a StoreLabelsRequest) where (Engine.Capabilities & ImapCapabilities.GMailExt1) == 0 — i.e. a non-Gmail IMAP server, or a setup where X-GM-EXT-1 is not advertised.

Common situations: Porting Gmail-specific label code to Dovecot/Outlook/other IMAP accounts; using a proxy or gateway that strips the X-GM-EXT-1 capability; expecting standard MessageFlags Store to manipulate Gmail labels.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at MailKit/Net/Imap/ImapFolderFlags.cs:481

						args.Add (Engine.EncodeMailboxName (label));
						break;
					}
				}
			}

			command.Append (')');
		}

		IEnumerable<ImapCommand> QueueStoreCommands (IList<UniqueId> uids, IStoreLabelsRequest request, CancellationToken cancellationToken)
		{
			if (uids == null)
				throw new ArgumentNullException (nameof (uids));

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

			if ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)
				throw new NotSupportedException ("The IMAP server does not support the Google Mail extensions.");

			CheckState (true, true);

			if (uids.Count == 0)
				return Array.Empty<ImapCommand> ();

			string action;

			switch (request.Action) {
			case StoreAction.Add:
				if (request.Labels == null || request.Labels.Count == 0)
					return Array.Empty<ImapCommand> ();

				action = request.Silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS";
				break;
			case StoreAction.Remove:
				if (request.Labels == null || request.Labels.Count == 0)
					return Array.Empty<ImapCommand> ();

View on GitHub (pinned to 9d3859a785)