This project is read-only.

connecting to exchange server mail box

Jul 20, 2011 at 10:32 AM


Can I use this library to connect to an exchange server mail box and read the email from that ?

Thanks and regards

Venkatesh. S

Jul 20, 2011 at 11:53 AM

Hi Venkatesh,

yes, you can connect to an exchange server, but you will need to use a secure SSL connection.

Regards Alex

Jul 21, 2011 at 2:40 AM


Should I use POP3 client or IMAP client. When I discussed the same with my organization infrastructure team. They say that it does not have an explicit POP3 address and just asked me provide the mail box address only. So instead of Pop3 address, like we do in VB6 MAPI, can I just provide the exchange server mail box to POP3 class  or IMAP client class and read the email. If one of this or either of this does not support this feature, Then please let me know if there are work arounds. Also if you could furnish some code samples for the same then it would be great.

Thanks and regards

Venkatesh. S



Jul 21, 2011 at 3:39 PM


I was able to connect to the exchange server mail box. Below is the sample code that I used

 using (var client = new ImapClient())
                client.Security = SecurityPolicies.Implicit; 
                client.Connect("<<Exchange server mail box>>",143);
	    int i = client.Messages.Count();
                                                                 client.Disconnect();             }
But in the line where I'm checking the message count (Marked in dark blue)  I get an exception {Cannot evaluate expression because the current thread is in a stack overflow state.}
If I say Client.Select("INBOX") before getting the count of message it hangs.
I just have only one test message in that inbox.
Could you please help me in this regard ?
Jul 21, 2011 at 5:23 PM
Edited Jul 22, 2011 at 1:52 AM

Hi Venkatesh,

technically an exchange server can be accessed by both the IMAP and the POP3 protocol, I would however not use POP3, if not absolutely necessary, since it is obsolete.

Unfortnuately this

int i = client.Messages.Count();

will not work, since the Count() extension method is not supported, you can read about supported extensions within the Documentation section. It should however throw a NotSupportedException.

The proper way to determine the message count is the following, assuming you are going to use the ImapClient.


using(var client = new ImapClient()) {
    client.Security = SecurityPolicies.Explicit;
    client.Connect("", 993);
    client.Authenticate("username", "password");

    if(!client.IsAuthenticated) {
        // handle invalid credentials

    var response = client.Select("INBOX");
    if(!response.IsOk) {
        // handle connection error

    var messageCount = response.MailboxInfo.Exists;




Jul 22, 2011 at 3:21 AM

Hi Alex,

In the client.connect I had provided the exchange server mailbox which of the format <<serverName>>.<<Doamin name>>. The IsAuthenticate is false. I had used TLS for authenticaion as SSL was failing. If you could see my earlier post client.Select("INBOX") is hanging. If you could rememeber about the MAPI API's that we used in VB6 days, I need a .NET equivalent of that as a managed component and I was trying to use this library in that context. As stated earlier My clients access their email using Outlook without an IMAP end point and they would also want the application to do that. Please tell me if this would help in achieving the same.

Thanks and regards

Jul 22, 2011 at 2:01 PM

Hello Venkatesh,

you will not be able to use this library with an exchange server by using an unencrypted connection. I am not 100% sure, but our Exchange does not support TLS, which means the connection will commence unencrypted.

When no encryption is negotiated the Exchange server enforces NTLM or KERBEROS authentication, both SASL mechanics are not yet supported by this library, therefor your authentication fails.

You will need to use SSL over port 993 to establish a connection. In addition I suggest using the Debug libraries, since they log all traffic from and to the server.

The only explanation for the hanging is that the library does not recognize the exchange servers response and therefor waits for the "termination message", if you can post your output log I can help you further.

Further more I used MAPI only once and it was horrible, I have no clue what it's full capabilities are and if IMAP covers them all or not.