简体   繁体   中英

Connecting to outlook.com in C# using AE.Net.Mail

I cannot connect to any mail accounts to retrieve emails using the AE NET Mail IMAP library. I've used it a while ago and it's good, but I've come back to it and in a new project it's not working for any email account. I have the following code:

        using (var client = new AE.Net.Mail.ImapClient(
            "mail.live.com",
            "myemail@outlook.com",
            "password_SV",
            ImapClient.AuthMethods.Login, 993, false
            ))
        {
            client.SelectMailbox("INBOX");
            AE.Net.Mail.MailMessage[] mailmessage = client.GetMessages(0, 5, false, true);

            foreach (AE.Net.Mail.MailMessage msg in mailmessage)
            {
                collection.Add(new Message()
                {
                    Id = msg.MessageID,
                    Sender = msg.Sender,
                    Subject = msg.Subject,
                    Content = msg.Body
                });
            }
            client.Logout();
            client.Disconnect();

            list.ItemsSource = collection;

But for some reason it just keeps loading (the spinning loading cursor) and the whole UI blocks up. After waiting for 10 minutes - absolutely nothing happens. It just keeps loading, and loading and loading. What am I doing wrong? How can we retrieve mail? I have also tried other accounts, like gmail, and my own one, but the same issues. How can we retrieve mail from outlook.com?

I cannot connect to Outlook, but I can now connect to my other mail accounts. Most examples have the folder names in all caps, but this won't work for me.

I changed .GetMessages("INBOX"); to .GetMessages("Inbox"); and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM