0

I am finding that I am unable to connect to outlook.office365.com's IMAP server using AE.Net.Mail. The code is very simple:

this._imapClient = new ImapClient(imapServer, username, password, AE.Net.Mail.AuthMethods.Login, port, enableSSL)

I find that I can connect to GMail with no issues, but office365 outlook will not connect, I keep getting timeouts. I've verified the IMAP settings by putting them in to Outlook and in to Thunderbird.

Has anyone else had trouble connecting AE.Net.Mail to Office365's IMAP server?

gnychis
  • 7,289
  • 18
  • 75
  • 113

2 Answers2

2

AE.Net.Mail is quite buggy and has not seen any development in over a year last I checked. I would recommend using MailKit instead.

I just confirmed that MailKit works with Office365.com with the following code snippet:

using (var client = new ImapClient ()) {
    client.Connect ("outlook.office365.com", 993, true);
    client.Authenticate ("username", "password");

    // get the unread messages
    var uids = client.Inbox.Search (SearchQuery.NotSeen);
    foreach (var uid in uids) {
        var message = client.Inbox.GetMessage (uid);
    }

    client.Disconnect (true);
}

Hope that helps.

jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • Thanks for this answer. Also having trouble getting new unread gmail messages with ae.net.mail... so I will try MailKit also – gnychis Jun 18 '15 at 13:00
  • If you have any questions, you can add an issue to https://github.com/jstedfast/MailKit/issues or you can find my email address on my github page. – jstedfast Jun 18 '15 at 13:01
  • where might be a good example that shows how to get only unread messages back as a list? – gnychis Jun 18 '15 at 13:34
  • I've just updated the answer to show how to get the unread messages. – jstedfast Jun 18 '15 at 14:26
  • thanks much! Trying to replace AE.Net.Mail in my system with MailKit now. Will let you know if I get stuck on anything else. – gnychis Jun 18 '15 at 14:34
  • Is it possible to get a MailKit.UniqueID from a MimeKit.MimeMessage? As in, if I return a MimeKit.MimeMessage to a function, will it still have access to its UID in some way? I see `MimeKit.MimeMessage.MessageID` but that is of type int, so I'm not sure that it's a UID – gnychis Jun 18 '15 at 14:51
  • Seems like you don't provide access to `UID`, so I cached it. One more question... with IMAP do I need to refresh the inbox every so often before checking for unread messages? I'm finding that new messages are coming in, but `client.Inbox.Count()` doesn't change and they don't show up in `SearchQuery.NotSeen` ... I have to reconnect to the mail server to see the messages. – gnychis Jun 18 '15 at 18:49
  • UIDs are not stored on the messages because IMAP doesn't store them on the messages. When you cache them, make sure you track the `folder.UidValidity` value as well, because you'll need to wipe your cache if that value changes. An IMAP server will only notify the client of new messages in response to a few commands: FETCH and NOOP are 2 that I know of off the top of my head. Subscribe to the `folder.CountChanged` event and call `client.NoOp();` – jstedfast Jun 18 '15 at 19:08
  • woof... never would I have thought I'd need to call something like client.NoOp() to get a ntoification of new messages. Do you have documentation for this kind of stuff somewhere that I'm ignoring, or are you still working on building documentation? I don't know the IMAP protocol well, just in the market for a good client :) – gnychis Jun 18 '15 at 19:11
  • Check out http://www.mimekit.net/docs/html/M_MailKit_Net_Imap_ImapClient_NoOp.htm – jstedfast Jun 18 '15 at 19:23
  • IMAP is my current priority for improving the documentation for (mostly by writing samples), but as I'm sure you understand, it's a ton of work and I do this in my spare time :-) – jstedfast Jun 18 '15 at 19:24
  • Totally understandable! Thanks for the extremely low latency responses, it's a huge help. Adding a Noop definitely solved my problem. I'll definitely reference that sample code. – gnychis Jun 18 '15 at 19:27
  • Just updated the docs for IMAP NOOP a bit as well: https://github.com/jstedfast/MailKit/commit/c246816b76e91c0d0d1fdd5922eac684106e99ca – jstedfast Jun 18 '15 at 19:50
0

Found I am able to connect by increasing the timeouts:

    _imapClient.ServerTimeout = 120000;
    _imapClient.IdleTimeout = 120000;
    _imapClient.Connect(_imapServer, _port, _enableSSL, false);
    _imapClient.Login(_username, _password);
    _imapClient.SelectMailbox("Inbox");
gnychis
  • 7,289
  • 18
  • 75
  • 113