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

Free Support Forum - aspose.com

Gmail authentication fails

@mudassir.fayyaz

I tried the approach mentioned at https://docs.aspose.com/email/net/accessing-gmail-on-ssl/#connecting-to-the-mail-server for logging into gmail but it didn’t work. Google didn’t allow it.

Please try below snippet mentioned in above documentation page:
ImapClient imap = new ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”, 993, “[user@gmail.com](mailto:user@gmail.com)”, “pwd”);

What’s recommended approach for Aspose.Email to connect with Gmail?

@salman.sarfraz

Actually, Gmail allows to use several ways for user authorization on the server. You may use any of the following:

login/password is considered less secure then OAUTH authentication and you have to use OAUTH if you needs without less secured enabled. The following implementation will work with less secure.

        public static void TestImapClient()
        {
            using (ImapClient client = new ImapClient())
            {

            client.Timeout = -1;
            client.Host = "imap.gmail.com";
            client.Username = "test3@gmail.com";
            client.Password = "cccc";
                

            SecurityOptions securityOptions = SecurityOptions.SSLAuto;
                client.SecurityOptions = securityOptions;
                switch (securityOptions)
                {
                    case SecurityOptions.None:
                        {
                            client.Port = 143;
                            var f = client.ListFolders();
                            foreach (var imapFolderInfo in f)
                            {
                                Console.WriteLine(imapFolderInfo.Name);
                            }

                        }
                        break;
                    default:
                        {
                            client.Port = 993;
                            var f = client.ListFolders();
                            foreach (var imapFolderInfo in f)
                            {
                                Console.WriteLine(imapFolderInfo.Name);
                            }


                            //  ImapFolderInfo folderInfo = client.GetFolderInfo(ImapFolderInfo.InBox);
                        }
                        break;
                }
            }


            Console.WriteLine("Hello World!");
        }

Thanks @mudassir.fayyaz. I will give it a try.