+1 vote

Hi. I get that meesage when I try to connect to Gmail IMAP. What is wrong because all I did is copy-paste from this site. I corrected my login info, of course :)

by (250 points)
edited by

1 Answer

0 votes

It seems you are missing invocation of Imap.ConnectSSL. Here's the code that shows how to connect to Gmail IMAP server:

using(Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");  
    imap.UseBestLogin("pat@gmail.com", "password");

    imap.SelectInbox();
    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(email.Subject);
    }
       imap.Close();
}

MailForWindowsStore.dll

If you are using MailForWindowsStore.dll, then ConnectSSL method is async - you must await it:

using(Imap imap = new Imap())
{
    await imap.ConnectSSL("imap.gmail.com");
    await imap.UseBestLogin("pat@gmail.com", "password");
by (301k points)
edited by
@Limilabs support I get error with that code, but if I use UseBestLoginAsync I get an error "Last network operation failed".

This is my code:

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLoginAsync("*****", "*****");
    imap.SelectInbox();
If you are using MailForWindowsStore.dll, ConnectSSL is async method - you must await it:

await imap.ConnectSSL("imap.gmail.com");
...