Connecting to IMAP Server

The ImapClient class allows applications to manage IMAP mailboxes using the IMAP protocol. The ImapClient class is used to connect to IMAP mail servers and manage emails in the IMAP email folders.

The ImapClient class allows connecting to any type of IMAP server. It can be used to connect to Non-SSL as well as SSL enabled IMAP servers.

Connect to IMAP Server

In order to connect to an IMAP server, you need to create an instance of the ImapClient class, specify the host name, user name and password as shown in the following code sample.

Connect to an SSL-Enabled IMAP server

In order to connect to an SSL-enabled IMAP server, options from the SecurityOptions class can be specified as required. This is shown in the following code sample by connecting to Gmail server.

Connect to Server using HTTP Proxy

Connecting to Server in Read-Only mode

The ImapClient class provides a ReadOnly property which when set to true, indicates that no changes should be made to the permanent state of the mailbox. The following code sample demonstrates the use of ImapClient.ReadOnly property. It gets the count of unread messages, then fetches one message and then gets the count of unread messages again in read-only mode. The count of the unread messages remains the same indicating that the permanent state of the mailbox was not changed.