Read Emails from MS Exchange Server using C#

Read Emails from MS Exchange Server using C#

Microsoft Exchange Server is a platform that lets you manage contacts, emails, calendars, schedules and provides several collaboration features. With MS Exchange Server, you can deploy your own mail server without relying on third parties. MS Exchange Server can also be accessed from within your web, desktop, or mobile applications via web services. Thus, you can perform the mailing and calendering operations in your applications. In this article, you are going to learn how to connect to an Exchange Server and read emails using C#.

C# Exchange Server API – Free Download

Aspose.Email for .NET provides easy to use API in order to work with MS Exchange Server. It lets you connect to your mail server using Exchange Web Service (EWS) or Internet Message Access Protocol (IMAP). Once you are connected, you can access items in a mailbox within a few steps. You can install Aspose.Email for .NET via NuGet or download its DLL.

PM> Install-Package Aspose.Email

Connect to an Exchange Server using C#

Aspose.Email for .NET provides two ways to connect to an instance of Exchange Server: EWS and IMAP. The following sections provide the steps of how to establish a connection using either of the ways.

Connect to an Exchange Server via EWS

The following are steps to connect to an MS Exchange Server using Aspose.Email for .NET.

The following code sample shows how to connect to Exchange Server via EWS using C#.

Connect to an Exchange Server via IMAP

In order to connect to an Exchange Server via IMAP, make sure that IMAP services are enabled on your server. Once done, follow the below steps to connect to the Exchange Server.

  • Create an instance of ImapClient class and provide host, username, and password to its constructor.
  • Set security options using ImapClient.SecurityOptions property.
  • Access the items in the mailbox using the ImapClient object.

The following code sample shows how to access Exchange Server via IMAP using C#.

Read Emails from Exchange Server using EWS in C#

The following are the steps to read email messages from Exchange Server using EWS.

The following code sample shows how to read emails from Exchange Server in C#.

Read Emails from Exchange Server using IMAP

The following are the steps to read emails from Exchange Server using IMAP.

The following code sample shows how to read emails from Exchange Server using IMAP.

Conclusion

In this article, you have learned how to connect to MS Exchange Server and read email messages using C#. Furthermore, the code samples have shown how to access Exchange Server using EWS and IMAP clients. You can explore more about the C# Email API using documentation.

See Also