More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Easy-to-use API
A typical EWS (Exchange Web Services) session goes through the following steps:
- Connect to an Exchange server.
- Validate the server certificate (this is done automatically by default, but you can perform the validation yourself).
- Log in - if required, authenticate with a user name and password or using a certificate.
- Select a folder, find email messages, download messages, etc.
- Disconnect.
Note: EWS protocol is only supported by Microsoft Exchange and Office 365.
Getting list of unread emails using Exchange Web Services (EWS)
The following code finds all unread e-mail messages and prints information about each of them:
// create EWS client instance using (var client = new Rebex.Net.Ews()) { // connect to Exchange server client.Connect(hostname, SslMode.Implicit); // authenticate client.Login(username, password); // to select folder to work with use either: // - client.FindFolder(EwsFolderId.Root, "folderName") // - predefined folder id var folder = EwsFolderId.Inbox; // get list of unread messages var list = client.Search( folder, EwsSearchParameter.IsRead(false)); // print some info foreach (EwsMessageInfo messageInfo in list) { Console.WriteLine("From: {0}", messageInfo.From); Console.WriteLine("To: {0}", messageInfo.To); Console.WriteLine("Subject: {0}", messageInfo.Subject); } // disconnect (not required, but polite) client.Disconnect(); }
' create IMAP client instance Using client = New Rebex.Net.Ews() ' connect to Exchange server client.Connect(hostname, SslMode.Implicit) ' authenticate client.Login(username, password) ' to select folder to work with use either ' - client.FindFolder(EwsFolderId.Root, "folderName") ' - predefined folder id Dim folder = EwsFolderId.Inbox ' get list of unread messages Dim list As EwsMessageCollection = client.Search( folder, EwsSearchParameter.IsRead(False)) ' print some info For Each messageInfo As EwsMessageInfo In list Console.WriteLine("From: {0}", messageInfo.From) Console.WriteLine("To: {0}", messageInfo.To) Console.WriteLine("Subject: {0}", messageInfo.Subject) Next ' disconnect (not required, but polite) client.Disconnect() End Using
Back to feature list...