This error is returned by the server (ImapResponseException tells you that).
"[Gmail]" folder can not be selected. This is the part of the IMAP server response to XLIST command:
S: * XLIST (\HasNoChildren \Inbox) "/" "Inbox"
S: * XLIST (\Noselect \HasChildren) "/" "[Gmail]"
Note the \Noselect flag.
[Gmail] acts as a root folder for other Gmail email folders, such as "[Gmail]/Drafts", "[Gmail]/Trash".
To check if the folder can be selected use FolderInfo.CanSelect class. It takes \NoSelect and \NonExistent flags into account.
using (Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("pat@gmail.com", "password");
foreach (FolderInfo folder in imap.GetFolders())
{
if (folder.CanSelect)
imap.Select(folder);
}
imap.Close();
}
If you are trying to download all emails, it may be better to use Gmail's "All Mail" folder. It contains all emails (both Sent and Received). Sometimes it is easier to work with labels instead of folders:
https://www.limilabs.com/blog/get-gmail-labels-for-specified-messages
https://www.limilabs.com/blog/label-message-with-gmail-label
In my experience it is easier to work with Gmail's IMAP this way.