{"record":{"id":"f5ecd257610c42e9","repo":"jstedfast/MailKit","slug":"the-imap-server-does-not-support-the-google-mail-extensions","errorCode":null,"errorMessage":"The IMAP server does not support the Google Mail extensions.","messagePattern":"The IMAP server does not support the Google Mail extensions\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderFlags.cs","lineNumber":481,"sourceCode":"\t\t\t\t\t\targs.Add (Engine.EncodeMailboxName (label));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcommand.Append (')');\n\t\t}\n\n\t\tIEnumerable<ImapCommand> QueueStoreCommands (IList<UniqueId> uids, IStoreLabelsRequest request, CancellationToken cancellationToken)\n\t\t{\n\t\t\tif (uids == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (uids));\n\n\t\t\tif (request == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (request));\n\n\t\t\tif ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)\n\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support the Google Mail extensions.\");\n\n\t\t\tCheckState (true, true);\n\n\t\t\tif (uids.Count == 0)\n\t\t\t\treturn Array.Empty<ImapCommand> ();\n\n\t\t\tstring action;\n\n\t\t\tswitch (request.Action) {\n\t\t\tcase StoreAction.Add:\n\t\t\t\tif (request.Labels == null || request.Labels.Count == 0)\n\t\t\t\t\treturn Array.Empty<ImapCommand> ();\n\n\t\t\t\taction = request.Silent ? \"+X-GM-LABELS.SILENT\" : \"+X-GM-LABELS\";\n\t\t\t\tbreak;\n\t\t\tcase StoreAction.Remove:\n\t\t\t\tif (request.Labels == null || request.Labels.Count == 0)\n\t\t\t\t\treturn Array.Empty<ImapCommand> ();","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderFlags.cs#L463-L499","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use standard IMAP flags instead: Store with MessageFlags (or custom flags if the server supports KEYWORDS).","Branch on capability: call label APIs only when (client.Capabilities & ImapCapabilities.GMailExt1) != 0, otherwise use flags or app-level metadata.","Connect to the actual Gmail endpoint (imap.gmail.com) so X-GM-EXT-1 is advertised; avoid capability-stripping proxies.","If Gmail-specific semantics are essential, use the Gmail REST API instead of IMAP."],"exampleFix":"// before\nfolder.AddLabels(uids, new [] { \"Important\" }); // throws on non-Gmail server\n// after\nif ((client.Capabilities & ImapCapabilities.GMailExt1) != 0) {\n    folder.AddLabels(uids, new [] { \"Important\" });\n} else {\n    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));\n}","handlingStrategy":"fallback","validationCode":"bool gmailExt = (client.Capabilities & ImapCapabilities.GMailExt1) != 0;\nif (gmailExt) {\n    folder.AddLabels(uids, labels);\n} else {\n    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));\n}","typeGuard":null,"tryCatchPattern":"try {\n    folder.AddLabels(uids, labels);\n} catch (NotSupportedException) {\n    // non-Gmail server: fall back to standard flags or app-side metadata\n    folder.Store(uids, new StoreFlagsRequest(StoreAction.Add, MessageFlags.Flagged));\n}","preventionTips":["Check ImapCapabilities.GMailExt1 before any label API call.","Design label handling to degrade to standard flags/keywords on other servers.","Connect to imap.gmail.com directly; avoid proxies that hide X-GM-EXT-1.","Consider the Gmail REST API when Gmail-specific semantics are essential."],"tags":["imap","mailkit","gmail","labels","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}