Not being Able to download messgaes from gmail

Topics: Help requests, Issues
Aug 19, 2016 at 9:28 AM
Edited Aug 19, 2016 at 9:28 AM
I have been trying for hours here when i execute the function below all get is "Object reference not set to an instance of an object" error, where am i going wrong?

public void imapx()
    {
        var client = new ImapClient("imap.gmail.com", true);
        if (client.Connect())
        {
            client.Login("username", "password");
            client.Behavior.MessageFetchMode = MessageFetchMode.Full;
            client.Behavior.AutoPopulateFolderMessages = true;
            var inbox = client.Folders.Inbox.Messages;
            inbox.Download();
        }

    }