Aspose.Email  for .NET

Retrieve Emails via EWS in C#

Introducing Aspose.Email functionality to receive emails programmatically via Microsoft Exchange server in C#

  Download Free Trial

C# Receive Email API & Exchange Web Services Integration

Aspose.Email for .NET offers a comprehensive receive email API designed to simplify email handling within your C# applications. By leveraging Exchange Web Services (EWS), this API enables you to efficiently retrieve emails from your Microsoft Exchange server. Whether you’re building custom email clients or integrating email receiving features into enterprise-level software, Aspose.Email for .NET ensures smooth integration with Exchange, while providing powerful tools to manage and automate email operations.

How To Receive Emails via EWS in C#

Aspose.Email API offers a IEWSClient interface, you can connect to an Exchange server, authenticate users, and retrieve messages with ease. The API provides comprehensive support for common email operations, including filtering emails based on specific criteria, managing attachments, and handling email flags.

Connect to Exchange Server

To start receiving emails, use the EWSClient.GetEWSClient method to instantiate the IEWSClient interface and connect your application to an Exchange server. This process requires specifying the server URL and credentials for authentication.

Connect to EWS using C#

var client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password");

List Messages

Once connected, the C# receive email API provides methods like ListMessages to retrieve emails from the Inbox or any other folder. Emails can be fetched based on parameters like date range or unread status, making it ideal for sorting and filtering messages.

List Messages in C#

var messages = client.ListMessages(client.MailboxInfo.InboxUri);

Fetch Messages

Iterate through a collection of email messages retrieved from an Exchange server and print the subject of each message to the console. Using the client.FetchMessage method, it retrieves the complete email message, ensuring that all content (including body and attachments) is fetched for further processing.

Fetch Messages in C#

foreach (var message in messages)
{
    Console.WriteLine("Subject: " + message.Subject);
    client.FetchMessage(message);
}

Handling Attachments and Flags

Aspose.Email for .NET also simplifies the handling of email attachments and flags (e.g., read/unread status). You can programmatically download attachments or mark emails as read/unread directly from your C# application.

Handling Email Attachments and Flags

// Handling attachments
    foreach (var attachment in fetchedMessage.Attachments)
    {
        Console.WriteLine("Attachment: " + attachment.Name);
    }
    
    // Mark email as read
    client.SetReadFlag(messageUri, true);

This is also possible through its MapiMessage class.

Aspose.Email & EWS Advanced Features

Beyond basic email retrieval, the API offers more powerful functionalities:

  • Calendar management: it enables developers to create, update, and delete calendar events directly on the Exchange server.

  • Real-time Synchronization: the API supports EWS synchronization of mailbox folders, allowing applications to receive emails in real time and ensuring that local applications stay up-to-date with server-side changes, enabling users to access timely updates and stay ahead of their communication.

  • Total Automation: it can handle complex email rules and perform automated operations like moving, copying, or deleting messages based on custom conditions.

  • Communication Safety: The API’s built-in security features, such as support for OAuth and SSL encryption, ensure that communications between the application and Exchange servers remain secure.

About C# Library

Aspose.Email offers a comprehensive suite of functionalities that empower developers to seamlessly interact with email communication within their applications. From creating and customizing messages with attachments and formatting to parsing incoming emails for essential data extraction, it simplifies the intricate process of their manipulation. The library’s adept attachment handling ensures smooth access to important files, enhancing user experiences. With its support for various email protocols and services, including IMAP, POP3, EWS, and MS Graph, the API provides a unified solution for developers to build robust email applications that streamline communication, boost productivity, and offer a seamless user experience.

Get Started

To leverage the power of the API, you need just a minute to install the library into your project. You can do this by any of the most convenient ways:

  • using NuGet Package Manager
  • referencing the required assemblies
  • or simply by using the following command within the Package Manager Console in Visual Studio:
 

Command


PM> Install-Package Aspose.Email