We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ImapClient.SelectFolder Throws Exception with Gmail IMAP Oauth 2.0 Scope

I am trying to read gmail messages using Gmail IMAP Oauth. I want to use Oauth 2.0 scope “https://www.googleapis.com/auth/gmail.readonly but aspose fails with exception “Unable connect to server”.
When i use Oauth 2.0 scope “https://mail.google.com/” , It works fine.

string AccessToken = credential.Token.AccessToken;
ImapMessageInfoCollection messageInfoCol = null;
ImapClient client = null;
client = new ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”, 993, “[sangapankaj@gmail.com](mailto:sangapankaj@gmail.com)”, AccessToken, true);
{
try
{
client.SecurityOptions = SecurityOptions.SSLImplicit;
client.SelectFolder(“Inbox”); //Exception is raised here when i use gmail readonly scope
messageInfoCol = client.ListMessages();
foreach (ImapMessageInfo mess in messageInfoCol)
{
MailMessage mailMessage = client.FetchMessage(mess.UniqueId);

                }
            }
            catch (Exception e)
            {
                
            }

        }

/////////////////////////////////////////////////////

Test project “OauthTest.zip” OauthTest.zip (3.7 MB)
GCred.zip (430 Bytes)
(visual studio 2019) is attached.

@sangapankaj,
Thank you for the issue description. I will answer you as soon as possible.

@sangapankaj,
I logged the issue with ID EMAILNET-40356 in our tracking system. Our development team will investigate this case. I will inform you of any progress.

@sangapankaj,
Our development team investigated the issue. “https://www.googleapis.com/auth/gmail.readonly” scope is not related to the IMAP client. This scope is related to Google APIs (GmailClient). As declared here: The scope for IMAP, POP, and SMTP access is “https://mail.google.com/”.

Also, you may implement read-only access using the IMAP protocol. To do this, you need to use ImapClient.ReadOnly property as shown below:

using (ImapClient client = new ImapClient("host", 993, "login", "password"))
{
    client.ReadOnly = true;
    client.SelectFolder("Inbox");
}

In this case, IMAP EXAMINE command will be used instead of IMAP SELECT command.

Documents: Connecting to Server in Read-Only mode
API Reference: ImapClient.ReadOnly Property