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...
Advanced features
On this page:
The sample code on this page assumes you have already connected and authenticated to an Exchange server.
Accessing shared mailboxes
To perform an operation on a shared mailbox (or another mailbox), construct folder IDs specific to that mailbox and use them to work with the shared mailbox:
// create EWS client instance, connect, log in // ... // get ID of the 'Inbox' folder in a shared mailbox 'shared@example.org' var folderId = new EwsFolderId(EwsSpecialFolder.Inbox, "shared@example.org"); // work with the shared mailbox folder bool exists = ews.FolderExists(folderId, "Orders");
' create EWS client instance, connect, log in ' ... ' get ID of the 'Inbox' folder in shared mailbox 'shared@example.org' Dim folderId = New EwsFolderId(EwsSpecialFolder.Inbox, "shared@example.org") ' work with the shared mailbox folder Dim exists = ews.FolderExists(folderId, "Orders")
Impersonate as another user
Impersonation makes it possible to use an account to log into Exchange server but then act as different user.
To enable impersonation, use Settings.Impersonation
property:
// create EWS client instance, connect, log in // ... client.Settings.Impersonation = new EwsImpersonation(); client.Settings.Impersonation.SmtpAddress = "impersonated.user@example.org";
' create EWS client instance, connect, log in ' ... client.Settings.Impersonation = New EwsImpersonation() client.Settings.Impersonation.SmtpAddress = "impersonated.user@example.org"
To switch back to the logged-on user, disable impersonation by setting Settings.Impersonation
property
to null
:
// turn impersonation off client.Settings.Impersonation = null;
' turn impersonation off client.Settings.Impersonation = Nothing
Synchronization and cumulative updates of items and folders
Exchange servers make it possible to retrueve a set of items or folders that have been changed since previous checkpoint.
The first checkpoint identifier is obtained with the initial set of changes. In the next query, use the identifier to get changes that occured since the previous query.
To synchronize items, use GetUpdatedItems
method:
// create EWS client instance, connect, log in // ... // get 100 changes at most int maxChangesCount = 100; // get an initial set of changes EwsUpdatedItemsInfo changes = ews.GetUpdatedItems(folderId, EwsItemFields.Default, maxChangesCount, null); // ... // do some work with the changes // ... // later, get the next set of changes using a checkpoint from the last query changes = ews.GetUpdatedItems(folderId, EwsItemFields.Default, maxChangesCount, changes.Checkpoint);
' create EWS client instance, connect, log in ' ... ' get 100 changes at most Dim maxChangesCount As Integer = 100 ' get an initial set of changes Dim changes As EwsUpdatedItemsInfo = ews.GetUpdatedItems(folderId, EwsItemFields.Default, maxChangesCount, Nothing) ' ... ' do some work with the changes ' ... ' later, get next set of changes using a checkpoint from the last query changes = ews.GetUpdatedItems(folderId, EwsItemFields.Default, maxChangesCount, changes.Checkpoint)
To synchronize folders, use GetUpdatedFolders
method:
// create EWS client instance, connect, log in // ... // get initial set of changes EwsUpdatedFoldersInfo changes = ews.GetUpdatedFolders(folderId, null); // ... // do some work with the changes // ... // later, get the next set of changes using a checkpoint from the last query changes = ews.GetUpdatedFolders(folderId, changes.Checkpoint);
' create EWS client instance, connect, log in ' ... ' get an initial set of changes Dim changes As EwsUpdatedFoldersInfo = ews.GetUpdatedFolders(folderId, Nothing) ' ... ' do some work with the changes ' ... ' later, get the next set of changes using a checkpoint from the last query changes = ews.GetUpdatedFolders(folderId, changes.Checkpoint)
Resolving names
To resolve a name, use ResolveNames
method.
This searches among mailbox (user) names and contact names.
// create EWS client instance, connect, log in // ... // find all mailboxes and contacts with 'Joe' in name IList<EwsResolvedName> list = ews.ResolveNames("Joe"); // print info about mailboxes and contacts found foreach (var info in list) { Console.WriteLine(info.Name); Console.WriteLine(info.EmailAddress); }
' create EWS client instance, connect, log in ' ... ' find all mailboxes and contacts with 'Joe' in name Dim list As IList(Of EwsResolvedName) = ews.ResolveNames("Joe") ' print info about mailboxes and contacts found For Each info In list Console.WriteLine(info.Name) Console.WriteLine(info.EmailAddress) Next
Determining Exchange server version
Use properties of Ews.Server
object to retrieve information about the Exchange server:
// create EWS client instance, connect, log in // ... // print info about the server Console.WriteLine("Exchange server: {0} (version {1})", ews.Server.ProductName, ews.Server.Version);
' create EWS client instance, connect, log in ' ... ' print info about the server Console.WriteLine("Exchange server: {0} (version {1})", ews.Server.ProductName, ews.Server.Version)
Deleting permanenty or to a folder
UseDeleteMode
property to choose what to do when delete operation is invoked.
Enum | Description |
---|---|
EwsDeleteMode.MoveToDeletedItems | Deleted items are store in user's "Deleted Items" folder. Folder name can be differnet in different language versions. |
EwsDeleteMode.Permanent | Deleted items are removed permanently. |
Back to feature list...