Retrieving Gmail by Imap4Client is extremely slow.

Nov 18, 2013 at 11:08 PM
Hi all,

I used this class to fetch emails from Gmail:
public class MailRepository
    {
        private Imap4Client _client = null;

        public MailRepository(string mailServer, int port, bool ssl, string login, string password)
        {
            if (ssl)
                Client.ConnectSsl(mailServer, port);
            else
                Client.Connect(mailServer, port);
            Client.LoginFast(login, password);
        }

        public MessageCollection GetAllMails(string mailBox)
        {
            return GetMails(mailBox, "ALL");
        }

        public MessageCollection GetUnreadMails(string mailBox)
        {
            return GetMails(mailBox, "UNSEEN");
        }

        protected Imap4Client Client
        {
            get
            {
                if (_client == null)
                    _client = new Imap4Client();
                return _client;
            }
        }

        private MessageCollection GetMails(string mailBox, string searchPhrase)
        {
            Mailbox mails = Client.SelectMailbox(mailBox);
            MessageCollection messages = mails.SearchParse(searchPhrase);
            return messages;
        }
    }
It take so long to download emails and I think it is abnormal. Just wondering is anyone having this issue and please kindly share some possible solutions to me?

Thank you very much in advance.
Nov 19, 2013 at 6:01 PM
What is size a download emails and how long download?

PS. Sorry for my poor english
Nov 19, 2013 at 10:34 PM
Thanks Kadeshar, Just regular size of emails. I tried download emails without attachments. But it takes a few minutes, i don't know if this is the normal case.
Feb 9, 2014 at 10:31 PM
In my case the slow point was in the Imap4Client Login method. It was taking at least 10 seconds to login. I noticed there was a LoginFast method so I tried that and it took less than a second.