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. To connect to an IMAP server

  1. Create an instance of the ImapClient class.
  2. Specify the hostname, username, and password in the ImapClient constructor.

Once the ImapClient instance is initiated, the next call to any operation using this instance will connect to the server. The following code snippet shows you how to connect to an IMAP server using the steps above.

Connecting with SSL Enabled IMAP Server

Connecting with IMAP Server described how to connect to an IMAP server in four simple steps:

  1. Create an instance of the ImapClient class.
  2. Specify the hostname, username, and password.
  3. Specify the port.
  4. Specify the Security Options.

The process for connecting to an SSL enables IMAP server is similar but requires that you set another few properties:

  • Set Security Options to SSLImplicit.

The following code snippet shows how to

  1. Set a username, password, and port.
  2. Set security option.

Connecting to Server via Proxy

Proxy servers are commonly used to communicate with the outside world. In such cases, mail clients are not able to communicate over the Internet without specifying the proxy address. Aspose.Email provides support for versions 4, 4a and 5 of the SOCKS proxy protocol. This article provides a working sample of accessing the mailbox using a proxy mail server. To access the mailbox via a proxy server:

  1. Initialize SocksProxy with the required information, that is proxy address, port, and SOCKS version.
  2. Initialize ImapClient with host address, user name, password, and any other settings.
  3. Set the client’s SocksProxy property to the SocksProxy object created above.

The following code snippet shows you how to retrieve mailbox via a proxy server.

Connecting to Server via 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.