+2 votes

Hi,

I am checking Folders example. I configured gmail settings and get error in reading folders:

"An unhandled exception of type 'Limilabs.Client.IMAP.ImapResponseException' occurred in Mail.dll

Additional information: [NONEXISTENT] Unknown Mailbox: [Gmail] (now in authenticated state) (Failure)"

What can be done about this?

Regards,

Muhammad Usman

by
retagged by

1 Answer

0 votes
 
Best answer

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.

by (297k points)
Thanks for quick response.
I have resolved issue as mentioned above. But when i compare the message count with message count shown in gmail interface, the stats does not match for Inbox, All Mail etc. What can be done about it?
Gmail interface shows the number of conversations, not the number of messages. Each conversation includes one or more messages. You can group messages into conversations using GmailThreadId (https://www.limilabs.com/blog/get-gmail-thread-id, https://www.limilabs.com/blog/search-gmail-thread-id)
...